UIActivityViewController issue iOS 7 and iOS 8?

*爱你&永不变心* 提交于 2019-12-03 12:32:44
Bhumit Mehta

Following line is the issue

AVC.popoverPresentationController.sourceView = _webView;

You will have to put iOS8 condition in order popoverPresentationController is introduced for iOS 8 and later so you can not use it with iOS 7

For checking for iOS8 you can define a macro like found from here

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

And use it in following way.

     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];

   if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")){

        AVC.popoverPresentationController.sourceView = _webView;
   }
   [self presentViewController:AVC animated:YES completion:nil];

Refer this for more info about what has changed for UIActivityViewController in iOS8

A lot might argue that checking for existence of the class explicitly is better than checking a hard coded version number. UIPopoverPresentationController may be deprecated at some future point, or there might be a (future ?) device which does not support the class, like the iPhone never used to support UIPopoverController or UISplitViewController..

if (  NSClassFromString(@"UIPopoverPresentationController")   ) {

AVC.popoverPresentationController.sourceView = _webView;


}

In Swift, You can use '?' instead checking OS version. AVC.popoverPresentationController?.sourceView = _webView

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!