通过UIActivityViewController分享到Twitter / Facebook等导致崩溃 [英] Sharing via UIActivityViewController to Twitter/Facebook etc. causing crash

查看:135
本文介绍了通过UIActivityViewController分享到Twitter / Facebook等导致崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS8上,我正在使用UIActivityViewController与Facebook / Twitter等共享UIImage。它似乎工作正常,但今天它在我的iPad上运行代码时突然崩溃了。但是,它仍然可以在模拟器中正常工作。

On iOS8 I'm using a UIActivityViewController to share a UIImage to Facebook/Twitter etc. It seemed to be working fine, but today it suddenly started crashing when running the code on my iPad. However, it still works as expected in the simulator.

我的代码:

UIActivityViewController *controller =
[[UIActivityViewController alloc]
 initWithActivityItems:@[text, url, myImage]
 applicationActivities:nil];

[self presentViewController:controller animated:YES completion:nil];

崩溃后,Xcode吐出:

Upon crashing, Xcode spits out:


发现的扩展程序:{(
{id = com.apple.share.Facebook.post},
{id = com.apple.share.Twitter.post},
{id = com.apple.share.TencentWeibo.post},
{id = com.apple.share.SinaWeibo.post})}属性:{
NSExtensionActivationRule = {
extensionItems =(
{
attachments =(
{
registeredTypeIdentifiers =(
public.image
);
},
{
registeredTypeIdentifiers =(
public.plain-text
);
},
{
registeredTypeIdentifiers =(
public.url
);
}
);
}
);
};
NSExtensionPointName =(
com.apple.share-services,
com.apple.ui-services,
com.apple.services
); 2014-08-07 21:38:59.208 collageTest [279:11021] LaunchServices:invalidationHandler名为2014-08-07 21:38:59.212
collageTest [279:11016]发现的扩展名:{(
{id = com.apple.share.Flickr.post},
{id = com.apple.mobileslideshow.StreamShareService},
{id = com.apple.share.Twitter.post},
{id = com.apple.share.Facebook.post},
{id = com.apple.share.Vimeo.post},
{id = com.apple.share.SinaWeibo.post },
{id = com.apple.share.TencentWeibo.post})} for attributes:{
NSExtensionPointName =com.apple.share-services; 2014-08-07 21:38:59.216 collageTest [279:11021] LaunchServices:
invalidationHandler被叫

Discovered extensions: {( {id = com.apple.share.Facebook.post}, {id = com.apple.share.Twitter.post}, {id = com.apple.share.TencentWeibo.post}, {id = com.apple.share.SinaWeibo.post} )} for attributes: { NSExtensionActivationRule = { extensionItems = ( { attachments = ( { registeredTypeIdentifiers = ( "public.image" ); }, { registeredTypeIdentifiers = ( "public.plain-text" ); }, { registeredTypeIdentifiers = ( "public.url" ); } ); } ); }; NSExtensionPointName = ( "com.apple.share-services", "com.apple.ui-services", "com.apple.services" ); } 2014-08-07 21:38:59.208 collageTest[279:11021] LaunchServices: invalidationHandler called 2014-08-07 21:38:59.212 collageTest[279:11016] Discovered extensions: {( {id = com.apple.share.Flickr.post}, {id = com.apple.mobileslideshow.StreamShareService}, {id = com.apple.share.Twitter.post}, {id = com.apple.share.Facebook.post}, {id = com.apple.share.Vimeo.post}, {id = com.apple.share.SinaWeibo.post}, {id = com.apple.share.TencentWeibo.post} )} for attributes: { NSExtensionPointName = "com.apple.share-services"; } 2014-08-07 21:38:59.216 collageTest[279:11021] LaunchServices: invalidationHandler called


推荐答案

popoverPresentationController 是iOS 8的新手,并且会在iOS 7上崩溃。它在iPhone上也是零,因为它只在<$ c iPad上的$ c> UIPopover 。这是Christian在Swift中的答案,其中考虑了这些事实:

popoverPresentationController was new to iOS 8 and will crash on iOS 7. It'll also be nil on iPhone because it's only in a UIPopover on iPad. Here's Christian's answer in Swift, with those facts taken into account:

let controller = UIActivityViewController(activityItems: [text, url, myImage], applicationActivities: nil)

presentViewController(controller, animated: true, completion: nil)

if #available(iOS 8.0, *) {
    let presentationController = controller.popoverPresentationController
    presentationController?.sourceView = view
}



Swift 1.2(Xcode 6)



Swift 1.2 (Xcode 6)

let controller = UIActivityViewController(activityItems: [text, url, myImage], applicationActivities: nil)

presentViewController(controller, animated: true, completion: nil)

if controller.respondsToSelector("popoverPresentationController") {
    // iOS 8+
    let presentationController = controller.popoverPresentationController
    presentationController?.sourceView = view
}

这篇关于通过UIActivityViewController分享到Twitter / Facebook等导致崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆