在iOS 9 + Xcode 7.3中通过WhatsApp共享字符串+图像,收到错误。 iOS 8完美运行。 代码:
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];
NSArray *excludeActivities = @[UIActivityTypePrint,
UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypeAirDrop];
activityController.excludedActivityTypes = excludeActivities;
[activityController setValue:[NSString stringWithFormat:@"Test msg"] forKey:@"subject"];
[self presentViewController:activityController animated:YES completion:nil];
答案 0 :(得分:0)
在iOS 9
中,您需要在项目.plist
文件中添加以下内容:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
</array>
在.plist
中添加此内容后进行检查。
答案 1 :(得分:0)
我解决了使用此代码发布的问题:
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController
{
return @"";
}
- (id)activityViewController:(UIActivityViewController )activityViewController itemsForActivityType:(NSString )activityType
{
if ([activityType isEqualToString:@"net.whatsapp.WhatsApp.ShareExtension"]) {
NSString *strShare = @“Test string”;
NSString *string = [NSString stringWithFormat:@"whatsapp://send?text=%@",strShare];
NSURL *url = [NSURL URLWithString:[string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL: url];
return @"";
}
else
{
return sharingItems;
}
}
答案 2 :(得分:0)
您可以添加图片网址,因为无法共享图片。 像这样添加图片网址
NSArray *arrData = @[@"Post Title", @"imageURL"];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:arrData applicationActivities:nil];
NSArray *excludeActivities = @[UIActivityTypeAirDrop,
UIActivityTypePrint,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList];
activityVC.excludedActivityTypes = excludeActivities;
[self presentViewController:activityVC animated:YES completion:nil];