SLComposeViewController:这取决于是否Twitter的应用程序“没有Twitter账户”警报的不同的行为安装

问题描述:

我使用Twitter的分享下面的代码在我的应用程序:现在SLComposeViewController:这取决于是否Twitter的应用程序“没有Twitter账户”警报的不同的行为安装

SLComposeViewController *twitter = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; 
[twitter setInitialText:@"some text"]; 

twitter.completionHandler = ^(SLComposeViewControllerResult result) 
{ 
    // do something... 
    [topViewController dismissViewControllerAnimated:YES completion:nil]; 
}; 
[topViewController presentViewController:twitter animated:YES completion:nil]; 

,如果没有Twitter账户建立和如果Twitter的应用程序没有安装,我得到以下警告:

enter image description here

这也正是它应该,按下“取消”将关闭这两个警报VI新闻和Twitter撰写视图。按“设置”也会关闭这两个视图并打开设置。尼斯。

现在,如果没有Twitter账户设置,但Twitter的应用程序安装,我得到以下警告:

enter image description here

注意,没有“取消”,并没有“设置“按钮,只是一个”确定“按钮。如果按下,警报视图会消失,但Twitter撰写视图会保留在那里,并且“发布”按钮变灰。因此,用户需要再次按“取消”才能关闭撰写视图并自己进入设置。不太好。

请注意,它不会有所作为是否我检查服务的可用性呈现SLComposeViewController前:

[SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]; 

你知道,为什么会出现这种行为差异,如果有一个无论是否安装Twitter应用程序,都可以获得相同的行为方式?

测试iOS 9.2.1,iPad Air(第二代)& iPhone 6 Plus。

+0

我还向Apple发送了一个错误报告:https://openradar.appspot.com/25214135。 – Flo

检查[this](Opening the Settings app from another app)out。 滚动到底部,有一个答案尚未upvoted(怪异),包含图像。 那里的链接告诉你如何导航到你的应用程序的设置/推特。 下一步是查看使用ACAccountStore,检查是否没有用户通过数组登录。

let accountStore = ACAccountStore() 
let accountType = accountStore.accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierTwitter) 

accountStore.requestAccessToAccountsWithType(accountType, options: nil, completion: { (granted, error) in 
if (granted) { 
     let arrayOfAccts = accountStore.accountsWithAccountType(accountType) 
     if (arrayOfAccts.count > 0) { 
     //regular function of twitter 
     } 
     //else is when there are no accounts logged into twitter 
     else { 
     //bring up a custom UIAlertAction with two options; Cancel and Settings. 
     //settings should use the openURL to prefs:root=TWITTER 
     } 
} 

这将模仿当用户没有登录到Twitter和应用程序没有安装给你取消,并设置它的工作方式。至于为什么你得到不同的警报设置是超出我的,这可能是一个iOS苹果的事情。

这条线:

[SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]; 

检查是否安装了Twitter的应用程序。 希望这有助于。

+0

感谢您的回答,@Nathan!发布的解决方案工作得很好。不幸的是,用户必须确认访问Twitter帐户。我也使用RDC的链接解决方案来链接到设置应用程序,因为它似乎适用于iOS 6到9.但总而言之,我可能最终将所有东西保持原样,并且与原始错误一起生活,如果RDC的解决方案没有经过审查过程。这个风险和必要的账户请求可能是矫枉过正的,只是为了解决这个相当小的错误。但无论如何这是一个很好的解决方案。 – Flo