【问题标题】:How to invite users through my app on whatsapp and share content IOS?如何通过我的应用在whatsapp上邀请用户并分享内容IOS?
【发布时间】:2015-01-19 11:27:35
【问题描述】:

我已经尝试过这段代码,但它只显示 whatsapp 图标,但没有在上面发送内容。请提出我在做什么错

- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {

    self.documentationInteractionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
    self.documentationInteractionController.delegate = interactionDelegate;
    return self.documentationInteractionController;
}


-(void)btnClick{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"]; //here i am fetched image path from document directory and convert it in to URL and use bellow


    NSURL *imageFileURL =[NSURL fileURLWithPath:getImagePath];
    NSLog(@"imag %@",imageFileURL);

    self.documentationInteractionController.delegate = self;
    self.documentationInteractionController.UTI = @"net.whatsapp.image";
    self.documentationInteractionController = [self setupControllerWithURL:imageFileURL usingDelegate:self];
    [self.documentationInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];

}

【问题讨论】:

    标签: ios xcode6 share whatsapp invite


    【解决方案1】:

    在whatsapp上发送消息文本:

            NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Test%20message%20whatsapp!"];
    
            if ([[UIApplication sharedApplication] canOpenURL:whatsappURL]) {
                [[UIApplication sharedApplication] openURL: whatsappURL];
            } else {
                UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Your device doesn't support Whatsapp!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [warningAlert show];
            }
    

    编辑: 和图片:

        if ([[UIApplication sharedApplication] canOpenURL: [NSURL      URLWithString:@"whatsapp://app"]]){
    
    UIImage     * iconImage = [UIImage imageNamed:@"YOUR IMAGE"];
    NSString    * savePath  = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wai"];
    
    [UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];
    
    _documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
    _documentInteractionController.UTI = @"net.whatsapp.image";
    _documentInteractionController.delegate = self;
    
    [_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];
    
    
        } else {
            UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
        }
    

    看whatsapp:http://www.whatsapp.com/faq/en/iphone/23559013 这个回复:Share image/text through WhatsApp in an iOS app 如果你想有一个与 Whatsapp 集成的 ShareKit:https://github.com/heringb/ShareKit

    【讨论】:

    • 感谢您的快速回复,感谢您的支持。上面的代码可以很好地共享文本,但我需要共享 url,所以我需要将 NSString 转换为某种 html 类型的 URL。 ShareKit 有一些丢失的文件,它给出了很多错误。
    • 您可以在消息文本中分享链接:NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Download%20my%20application%20here:%20http://itunes .apple.com/app/id000000191"];
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-19
    • 1970-01-01
    • 2022-01-23
    • 2016-11-06
    • 1970-01-01
    • 2018-01-05
    • 1970-01-01
    相关资源
    最近更新 更多