2016-01-20 35 views
0

我剛剛通過添加所有必需的Facebook框架,調整我的info.plist,並在我的應用程序委託中添加方法以允許用戶使用Facebook登錄。我甚至在我的分析數據庫上測試並驗證了這些新數據。好極了。如何使我的SLComposeViewController可用於服務類型(Facebook)iOS swift

現在,我試圖添加一個按鈕,如果用戶通過Facebook登錄到我的應用程序,可以將信息分享給用戶的新聞傳播。這是我有:

@IBAction func tellFriends(sender: AnyObject) { 

    if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook) { // USER LOGGED IN USING FACEBOOK 

     let facebookSheet = SLComposeViewController(forServiceType: SLServiceTypeFacebook) 
     facebookSheet.setInitialText("Share on Facebook") 
     self.presentViewController(facebookSheet, animated: true, completion: nil) 

    } else { // USER DID NOT USE FB TO LOG IN 

     let alert = UIAlertController(title: "Accounts", message: "Please login to a Facebook account to share.", preferredStyle: UIAlertControllerStyle.Alert) 
     alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)) 
     self.presentViewController(alert, animated: true, completion: nil) 
    } 

} 

我得到的唯一結果是其他和我的警報控制器彈出。我驗證了我是通過Facebook登錄到應用程序的。我錯過了什麼?提前致謝。

回答

0

只是在開玩笑,這段代碼工作,只是不在模擬器中。一旦我插入手機,並嘗試它在那裏工作得很好。就像位置服務,通知和消息UI一樣;他們在實際的iPhone上工作,而不是在模擬器中工作。

相關問題