如果用户已安装Twitter,则需要在我的应用程序中打开tweet,然后在Twitter中打开,否则请提供Webview并呈现tweet。
我基本上可以通过以下方式实现这一目标。它有效,我对此感到满意。
但是,当最初提示在Twitter中打开时,如果用户单击“取消”,我想改为显示Webview。但是,当前,如果用户单击“取消”,则什么也没有发生,他们需要再次点击该供稿中的tweet项。
如果用户单击消息中的“取消”,是否有可能会进行回退?
func didSelectItemInFeed(_ selected: FeedItem) {
switch selected.item.type {
case .companyNews:
....
case .tweet:
guard
let username = selected.item.tweet?.displayName,
let appURL = URL(string: "twitter://status?id=\(selected.item.externalId)"),
let webURL = URL(string: "https://twitter.com/\(username)/status/\(selected.item.externalId)")
else { return }
let application = UIApplication.shared
if application.canOpenURL(appURL as URL) {
application.open(appURL as URL)
} else {
presentWebView(webURL)
}
default:
break
}
}
答案 0 :(得分:1)
使用以下内容完成您的功能:application.open(appURL as URL, completionHandler: {isSuccess in})()
func didSelectItemInFeed(_ selected: FeedItem) {
switch selected.item.type {
case .companyNews:
....
case .tweet:
guard
let username = selected.item.tweet?.displayName,
let appURL = URL(string: "twitter://status?id=\(selected.item.externalId)"),
let webURL = URL(string: "https://twitter.com/\(username)/status/\(selected.item.externalId)")
else { return }
let application = UIApplication.shared
if application.canOpenURL(appURL as URL) {
application.open(appURL as URL, completionHandler: { isSuccess in
// print here does your handler open/close : check 'isSuccess'
})()
} else {
presentWebView(webURL)
}
default:
break
}
}
答案 1 :(得分:0)
application.open有一个可选的完成处理程序:
application.open(appURL) { (success) in
print("Success \(success)")
}
您应该检查成功状态。