2016-10-06 40 views
0

我試圖導入twitter的社交框架,並在社交按鈕被按下時調用視圖。這是我的代碼,我得到「類型'GameOverScene'的值沒有成員'present'」,我試圖呈現視圖。當前視圖:Swift 3

if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeTwitter) { 
        let tweetController = SLComposeViewController(forServiceType: SLServiceTypeTwitter) 

        tweetController?.setInitialText("I Scored \(scoreNumber) on Gone Dots! You can try by downloading Gone Dots from the app store for free") 

        self.present(tweetController, animated: true, completion: true) 

       } else { 

        let alert = UIAlertController(title: "Account", message: "Plese log into Twitter", preferredStyle: UIAlertControllerStyle.alert) 

        alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) 

        alert.addAction(UIAlertAction(title: "Settings", style: UIAlertActionStyle.default, handler: { 
         (UIAlertAction) in 
         let settingsURL = NSURL(string: UIApplicationOpenSettingsURLString) 

         if let url = settingsURL{ 
          UIApplication.shared.openURL(url as URL) 
         } 

        })) 

        self.present(alert, animated: true, completion: true) 

       } 

回答

1

本方法是UIViewController的方法,這就是爲什麼你會得到錯誤。要在SKScene中演示,你可以這樣說。

view?.window?.rootViewController?.present(alert, animated: true, completion: true) 

我建議你谷歌如何使用UIActivityViewController這是現在做共享的最好方法。我甚至相信在某個地方看過那些舊的社交API已經被棄用了。 UIActivityViewController是它可以讓你分享到大量服務的途徑,包括第三方服務,你只需要使用1個API。這也意味着你只需要在你的應用中使用1個分享按鈕而不是多個按鈕。

希望這會有所幫助。

+0

非常感謝我使用UIActivityViewController及其工作 –