我使用此代碼在iOS應用程序的WhatsApp上共享圖像,但控制器總是處於else
的狀態。請給我一個解決方案。如何從我的iOS應用程序發送圖像或文本到whatsapp?
if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]])
{
UIImage *iconImage = [UIImage imageNamed:dict23[@"profileimg"]];
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。」消息... –
然後你在模擬器中運行它,你必須在裝有whats app的設備上運行它。 –