我正在为iPad制作一篇文章阅读应用程序.我已经整合了社交分享功能,这意味着用户可以在Facebook上分享文章和谷歌邮件.
我正在使用UIActivityViewController进行共享.
我正在使用UIActivityViewController进行共享.
有一个按钮项,当用户点击该UIActivityViewController打开.我更新Xcode 6
当我运行在模拟器上运行良好但是我运行在iOS 7的真实设备(iPad)上,该应用程序在点击按钮项目崩溃.
这是我的代码:
- (IBAction)ysshareAction:(id)sender { NSURL *linkURL = [NSURL URLWithString:_DetailModal1[4]];//article url NSMutableAttributedString *stringText = [[NSMutableAttributedString alloc] initWithString:_DetailModal1[0]];//_DetailModal1[0] contain article title//// [stringText addAttribute:NSLinkAttributeName value:linkURL range:NSMakeRange(0,stringText.length)]; NSArray * itemsArray = @[[NSString stringWithFormat:@"%@",_DetailModal1[0]],[NSURL URLWithString:_DetailModal1[4]]]; NSArray * applicationActivities = nil; UIActivityViewController * AVC = [[UIActivityViewController alloc] initWithActivityItems:itemsArray applicationActivities:applicationActivities]; AVC.popoverPresentationController.sourceView = _webView; [self presentViewController:AVC animated:YES completion:nil]; [AVC setCompletionHandler:^(NSString *act,BOOL done) { if([act isEqualToString:UIActivityTypeMail]) { ServiceMsg = @"Mail sent!"; } else if([act isEqualToString:UIActivityTypePostToTwitter]) { ServiceMsg = @"Article Shared!"; } else if([act isEqualToString:UIActivityTypePostToFacebook]) { ServiceMsg = @"Article Shared!"; } else if([act isEqualToString:UIActivityTypeMessage]) { ServiceMsg = @"SMS sent!"; } else if([act isEqualToString:UIActivityTypeAddToReadingList]) { ServiceMsg = @"Added to Reading List"; } else if([act isEqualToString:UIActivityTypeCopyToPasteboard]){ ServiceMsg = @"Copied Link"; } if ( done ) { UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:ServiceMsg message:@"" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil]; [Alert show]; } }]; }
帮助是赞赏!
解决方法
以下是问题
AVC.popoverPresentationController.sourceView = _webView;
你将不得不放置iOS8的条件popoverPresentationController被引入iOS 8和更高版本,所以你不能使用它与iOS 7
为了检查iOS8,您可以定义从here发现的宏
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
并以下列方式使用它.
NSURL *linkURL = [NSURL URLWithString:_DetailModal1[4]];//article url NSMutableAttributedString *stringText = [[NSMutableAttributedString alloc] initWithString:_DetailModal1[0]];//_DetailModal1[0] contain article title//// [stringText addAttribute:NSLinkAttributeName value:linkURL range:NSMakeRange(0,stringText.length)]; NSArray * itemsArray = @[[NSString stringWithFormat:@"%@",[NSURL URLWithString:_DetailModal1[4]]]; NSArray * applicationActivities = nil; UIActivityViewController * AVC = [[UIActivityViewController alloc] initWithActivityItems:itemsArray applicationActivities:applicationActivities]; if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")){ AVC.popoverPresentationController.sourceView = _webView; } [self presentViewController:AVC animated:YES completion:nil];
有关iOS8中UIActivityViewController的更改信息,请参阅this