iOS Share Extension crashes when sharing from iOS 11 Screenshot

╄→гoц情女王★ 提交于 2019-12-01 03:42:09

let url = data as! URL if let imageData = try? Data(contentsOf: url) {

The issue is because the data here is not a URL. It is a "public.image", try to convert to UIImage instead of Data.

In Objective C You can use following code for image that shared as screen shot. Screen shot having .png extension so use public.png instead of public.jpeg

if ([itemProvider hasItemConformingToTypeIdentifier:@"public.png"]){
            [itemProvider loadItemForTypeIdentifier:@"public.png" options:nil completionHandler: ^(id<NSSecureCoding> item, NSError *error) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    NSData *imgData;
                    if([(NSObject*)item isKindOfClass:[NSURL class]]) {
                        imgData = [NSData dataWithContentsOfURL:(NSURL*)item];
                    }
                    if([(NSObject*)item isKindOfClass:[UIImage class]]) {
                        imgData = UIImagePNGRepresentation((UIImage*)item);
                    }
 UIImage *image=[UIImage imageWithData:imgData];
});

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