我使用Facebook SDK和Twitter SDK进行登录和注册.
但他们都没有从一种常见的方法打开网址.就像我写的下面代码为Facebook,
func application(application: UIApplication,openURL url: NSURL,sourceApplication: String?,annotation: AnyObject) -> Bool { if(url.scheme == "fb1651015905222312") { return FBSDKApplicationDelegate.sharedInstance().application(application,openURL: url,sourceApplication: sourceApplication,annotation: annotation) } return true }
这工作正常,对于twitter我必须评论上面的方法,并写得像,
func application(app: UIApplication,options: [String : AnyObject]) -> Bool { if Twitter.sharedInstance().application(app,openURL:url,options: options) { return true } return true }
这适用于Twitter.
问题是我需要编写一个常用方法来在appDelegate中打开他们的URL.那我怎么克服它?
提前致谢.
注意:我们不能在app delegate中编写这两种方法.
解决方法
最后我找到了这个问题的解决方案.
斯威夫特3
func application(_ app: UIApplication,open url: URL,options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { if Twitter.sharedInstance().application(app,open:url,options: options) { return true } let appId = SDKSettings.appId if url.scheme != nil && url.scheme!.hasPrefix("fb\(appId)") && url.host == "authorize" { // facebook return SDKApplicationDelegate.shared.application(app,open: url,options: options) } return false }
对于Swift< 3 这是允许我为Facebook和Twitter编写URL的方法.
func application(app: UIApplication,options: [String : AnyObject]) -> Bool { if Twitter.sharedInstance().application(app,options: options) { return true } let sourceApplication: String? = options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String return FBSDKApplicationDelegate.sharedInstance().application(app,annotation: nil) }
感谢所有试图回答我问题的人.
谢谢.