2016-11-29 22 views
6

我正在与夫特3在iOS 10. sharedInstance()方法引发错误,当用户拒绝权限从系统或帐户以考虑不配置(例如到控制台“无法写入应用获取错误使用系统帐户进行​​身份验证“)。错误在进入关闭之前在控制台上显示。我不会在应用中向用户显示此错误警惕。这是我的代码:从Twitter.sharedInstance()夫特3的iOS 10

Twitter.sharedInstance().logIn { (session, error) in 
       if error != nil { 
       // print(error?.localizedDescription ?? " ") 
        return 
       }) 

我得到这个错误:

2016-11-29 14:49:09.023 CarReview[1254:31719] [TwitterKit] did encounter error with message "Unable to authenticate using the system account.": Error Domain=TWTRLogInErrorDomain Code=2 "User allowed permission to system accounts but there were none set up." UserInfo={NSLocalizedDescription=User allowed permission to system accounts but there were none set up.} 
2016-11-29 14:49:09.024 CarReview[1254:31719] [TwitterKit] No matching scheme found. 
2016-11-29 14:49:09.292 CarReview[1254:31719] [TwitterKit] did encounter error with message "Error obtaining user auth token.": Error Domain=TWTRLogInErrorDomain Code=-1 "<?xml version="1.0" encoding="UTF-8"?> 
<hash> 
    <error>Desktop applications only support the oauth_callback value 'oob'</error> 
    <request>/oauth/request_token</request> 
</hash> 
" UserInfo={NSLocalizedDescription=<?xml version="1.0" encoding="UTF-8"?> 
<hash> 
    <error>Desktop applications only support the oauth_callback value 'oob'</error> 
    <request>/oauth/request_token</request> 
</hash> 
} 

我想向用户展示这一点:“无法使用系统帐户验证用户允许的权限系统帐户,但什么都没有设置向上。”

回答

0

我不知道我理解你想要做什么,但你可能想打印的主线程结果:

Twitter.sharedInstance().logIn{(session, error) in 
    DispatchQueue.main.async{ 
     if error != nil { 
      print("Failed to login with Twitter/error:", error!.localizedDescription) 
     }else{ 
      print("succeeded") 
     } 
    } 
} 
+0

是不是我的意思。在关闭呼叫之前在控制台上显示错误,我对此没有影响。我不会向用户显示这个错误。控制台上的错误显示了它自己。 –

+0

如果你不希望它在控制台关闭前被印刷出来,您需要在我的答案添加DispatchQueue.main.async等。 –

+0

尽管我没有控制错误,但是控制台出错了,但它不是我的打印功能。 –

0

OK,我使用此代码来通知用户的一些错误:

if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeTwitter) { 
      if ACAccountStore().accountType(withAccountTypeIdentifier: ACAccountTypeIdentifierTwitter).accessGranted { 

       Twitter.sharedInstance().logIn{ 
        (session, error) in 
        if error != nil { 
         self.showAlert(title: "Twitter - Error", message: (error?.localizedDescription)!) 
         return 
        } 

        guard let token = session?.authToken else { return } 
        guard let secret = session?.authTokenSecret else { return } 

        let credential = FIRTwitterAuthProvider.credential(withToken: token, secret: secret) 
        FIRAuth.auth()?.signIn(with: credential, completion: { (user, error) in 
         if error != nil { 
          self.showAlert(title: "Firebase (Twitter)", message: (error?.localizedDescription)!) 
          return 
         } 

         self.showAlert(title: "Firebase (Twitter)", message: "Logged to Firebase via Twitter.") 
        }) 
       } 
      } else { 
       showAlert(title: "Twitter - Error", message: "Give access to the system Twitter account.") 
      } 
     } else { 
      showAlert(title: "Twitter - Error", message: "No system accounts set up.") 
     } 

但它不是我想要的:/

0

您需要使用withMethods并使用systemAccounts,而不是基于Web或全部使用iOS Twitter的设置中指定。下面的代码是在斯威夫特3:

twitSharedInstance.logIn(withMethods: .systemAccounts) { (session :TWTRSession?, error :Error?) in 
     if (error != nil) { 
      if (session != nil) { 
       //We have logged into Twitter. 
      } 
     } 
    } 
0

我会尽力去猜测你的问题其实是:

“我在控制台的错误,但回调不叫,这样我就可以” t怎么办?

由于您的consumerKeyconsumerSecret未在Info.plist中设置,您会收到这些错误。您需要正确install Twitter SDK

这是什么写在注释logIn(completion:)

@warning This method requires that you have set up your consumerKey and consumerSecret .

的Info.plist应该有这样的事情(注意<key>consumerKey</key><key>consumerSecret</key>字符串):

<key>Fabric</key> <dict> 
    <key>APIKey</key> 
    <string> YOUR API KEY </string> 
    <key>Kits</key> 
    <array> 
     <dict> 
      <key>KitInfo</key> 
      <dict> 
       <key>consumerKey</key> 
       <string> YOU PROBABLY MISSED YOUR CONSUMER KEY </string> 
       <key>consumerSecret</key> 
       <string> YOU PROBABLY MISSED YOUR CONSUMER SECRET </string> 
      </dict> 
      <key>KitName</key> 
      <string>Twitter</string> 
     </dict> 
    </array> 
</dict> 
10

我面临着同样的问题,如问题。 我刚才设置的回调URL到Twitter的应用程序和解决的问题。

转到https://apps.twitter.com/app - >设置 - >回调URL和更新设置进行保存。

+2

我需要在回拨网址中输入什么内容? – user3033437

+1

您可以添加的任何有效URL。 –