我使用了UIActivityViewController和共享选项。
NSURL *url =[NSURL URLWithString:@"google.com"];
UIImage *img = [UIImage imageNamed:@"myImage"];
NSMutableArray *ar2 = [NSMutableArray arrayWithObjects:UIActivityTypePostToWeibo, UIActivityTypeSaveToCameraRoll, UIActivityTypeMessage, UIActivityTypePrint, UIActivityTypeAssignToContact, nil];
NSArray *itemsToShare = @[textToShare,url];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
[activityVC setValue:@"Sample - Share" forKey:@"subject"];
activityVC.excludedActivityTypes = ar2;
[self presentViewController:activityVC animated:YES completion:NULL];
但它显示有一些白色视图和AirDrop名称为“null”。任何人都可以建议我一个解决方案......
答案 0 :(得分:0)
我测试了你的代码,它对我来说很好。我正在使用iPod5 touch和iOS 7.1.2 我有一点建议。尝试延迟调用您的代码。像:
[self performSelector:@selector(shareActivityView) withObject:nil afterDelay:0.5];
您的方法shareActivityView似乎:
-(void)shareActivityView
{
NSURL *url =[NSURL URLWithString:@"google.com"];
UIImage *img = [UIImage imageNamed:@"myImage"];
NSMutableArray *ar2 = [NSMutableArray arrayWithObjects:UIActivityTypePostToWeibo, UIActivityTypeSaveToCameraRoll, UIActivityTypeMessage, UIActivityTypePrint, UIActivityTypeAssignToContact, nil];
NSArray *itemsToShare = @[textToShare,url];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
[activityVC setValue:@"Sample - Share" forKey:@"subject"];
activityVC.excludedActivityTypes = ar2;
[self presentViewController:activityVC animated:YES completion:NULL];
}
这很奇怪,但有时却有效。