2014-11-24 89 views
2

工作如果發送短信到WhatsApp的:WhatsApp的共享文本和圖像沒有在IOS

NSString *msg = @"Some Text"; 
NSString *urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@",msg]; 
NSURL *whatsappURL = [NSURL URLWithString:[urlWhats stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) { 
    [[UIApplication sharedApplication] openURL: whatsappURL]; 
} 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:

if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]]){ 

    UIImage* iconImage = [self captureScreen];// this will return a 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的是沒有任何文本打開文本共享和圖像也沒有得到共享。請幫幫我。

+0

http://stackoverflow.com/questions/8354417/share-image-text-通過whatsapp-in-an-ios-app看看這個 – Sport 2014-11-24 12:52:52

+0

我已經嘗試過,但它不工作 – Praveen 2014-11-24 13:15:19

+0

什麼是錯誤 – Sport 2014-11-24 13:20:06

回答

2

您是否向您的plist添加了「LSApplicationQueriesSchemes」?

  1. 轉到您的項目/支持文件/ YourProjectName-Info.plist XCode項目瀏覽器。
  2. 添加新的鍵值對。重點: LSApplicationQueriesSchemes類型:Array添加一個新的字符串項 「WhatsApp的」

請試試這個,讓我知道,如果它仍然沒有工作。

0

注: - 您只可以分享文字或圖像,無論是在分享共同的WhatsApp沒有從WhatsApp的側工作

/* 
    //Share text 
    NSString *textToShare = @"Enter your text to be shared"; 
    NSArray *objectsToShare = @[textToShare]; 

    UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil]; 
    [self presentViewController:activityVC animated:YES completion:nil]; 
    */ 

    //Share Image 
    UIImage * image = [UIImage imageNamed:@"images"]; 
    NSArray *objectsToShare = @[image]; 

    UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil]; 
    [self presentViewController:activityVC animated:YES completion:nil]; 
相關問題