我的代码实现非常简单:
if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeTwitter) {
guard let composeViewController = SLComposeViewController(forServiceType: SLServiceTypeTwitter) else {
return
}
composeViewController.add(image)
composeViewController.setInitialText("some text")
present(composeViewController, animated: true, completion: nil)
}
但是,当Twitter屏幕在应用程序上打开时,对话框中没有显示图像。
如果我在模拟器中运行相同的代码,它可以正常工作。
当我尝试在真实设备中发布时,即使没有图像,帖子也永远不会到达Twitter。
评论add(image code)
喜欢:
//composeViewController.add(image)
通过这一行注释掉帖子没有问题,它被发布到Twitter。
在真实设备中运行应用程序时,这是控制台文本:
[core] SLComposeViewController isAvailableForServiceType com.apple.social.twitter
[core] SLComposeViewController isAvailableForServiceType got serviceType com.apple.social.twitter isAvailable 1
[core] SLComposeViewController isAvailableForServiceType com.apple.social.twitter returning 1
[core] SLComposeViewController initWithServiceType: com.apple.social.twitter
[core] SLComposeViewController initWithServiceType got extension <NSExtension: 0x174170200> {id = com.apple.share.Twitter.post} for identifier com.apple.share.Twitter.post
[core] SLComposeViewController initWithExtension: <NSExtension: 0x174170200> {id = com.apple.share.Twitter.post} requestedServiceType: com.apple.social.twitter
[core] SLComposeViewController initWithExtension got override extension <NSExtension: 0x174170200> {id = com.apple.share.Twitter.post}
[core] addImage start
[core] viewWillAppear
[core] SLComposeViewController building implicit NSExtensionItem from array of 1 _itemProviders
[core] SLComposeViewController setting first extensionItem.attributedContentText to 'some text'
[core] SLComposeViewController about to instantiate remote view controller with array of 1 NSExtensionItems
[core] viewDidAppear
[core] SLComposeViewController finished instantiate remote view controller <SLRemoteComposeViewController: 0x12610d200> error (null) extension request identifier 1E964C0A-778C-498C-A092-C1D9C3F8C542
[core] SLComposeViewController received remoteViewController of class SLRemoteComposeViewController, and setting its delegate to self
[core] HOST: Successfully loaded remote SLComposeVC
[core] [remoteViewController setupRemoteViewController]
[core] Finished setting up remote view controller
没什么特别的