2015-02-24 53 views
0

我想從我的應用程序分享的Google+帖子,我已經做了所有在本教程: https://developers.google.com/+/mobile/ios/share#adding_basic_sharing共享斯威夫特

多於1次......

的問題是:

@IBAction func postToGoogle(sender: UIButton) { 

    var shareDialog : GPPShareBuilder = GPPShare().shareDialog() 

    shareDialog.setPrefillText("Check This out") 

    shareDialog.setURLToShare(NSURL(string: "https://developers.ggoe.com/+/")) 

    shareDialog.setCallToActionButtonWithLabel("BookMark", URL: NSURL(string: "https://developers.google.com/+/mobile/ios/"),deepLinkID: "") 

    shareDialog.open() 

} 

當按下postToGoogle總是得到這個控制檯:

「你必須指定| CL ientID |爲| GPPSignIn |'

但在我viewDidLoad中:

signIn = GPPSignIn.sharedInstance() 
    signIn?.shouldFetchGoogleUserEmail = true 
    signIn?.shouldFetchGoogleUserID = true 
    signIn?.shouldFetchGooglePlusUser = true 

    signIn?.clientID = "89239876213876321yuwqiuhwq.apps.googleusercontent.com" 
    signIn?.scopes = [kGTLAuthScopePlusLogin] 
    signIn?.delegate = self 

正如你可以看到我已經分配的客戶端ID。即使我登錄時,一切正常。

ps:此客戶端ID是假的。

請幫我解決這個錯誤。 在此先感謝 ADS

回答

0

所以,我發現了問題:

在vewDidLoad補充說:

gppShare = GPPShare.sharedInstance() 

改變德按鈕動作:

var shareDialog = gppShare?.shareDialog() 

    shareDialog?.setPrefillText("Check This out") 

    shareDialog?.setURLToShare(NSURL(string: "https://developers.google.com/+/")) 

    shareDialog?.setCallToActionButtonWithLabel("BookMark", URL: NSURL(string: "https://developers.google.com/+/mobile/ios/"),deepLinkID: "") 

    shareDialog?.open() 

現在它調用共享對話框。但它仍然缺少深層次的聯繫。

+0

您是否在開發人員控制檯中啓用了深層鏈接? – class 2015-02-25 18:52:33

+1

是的,我做到了。它的工作現在:) – 2015-02-26 12:50:51

0

下面的代碼對我的作品:

@IBAction func shareClicked(sender: AnyObject) { 
    var shareDialog = GPPShare.sharedInstance().nativeShareDialog(); 

    // This line will fill out the title, description, and thumbnail from 
    // the URL that you are sharing and includes a link to that URL. 
    shareDialog.setURLToShare(NSURL(fileURLWithPath: kShareURL)); 

    shareDialog.open(); 
} 

Full project sources on GitHub

1

這是爲我工作,而無需使用谷歌加SDK:

@IBAction func googlePlusShare(sender: AnyObject) { 

    let urlstring = "https://developers.google.com/+/mobile/ios/share/basic-share" 

    let shareURL = NSURL(string: urlstring) 

    let urlComponents = NSURLComponents(string: "https://plus.google.com/share") 

    urlComponents!.queryItems = [NSURLQueryItem(name: "url", value: shareURL!.absoluteString)] 

    let url = urlComponents!.URL! 

    if #available(iOS 9.0, *) { 
     let svc = SFSafariViewController(URL: url) 
     svc.delegate = self 
     self.presentViewController(svc, animated: true, completion: nil) 
    } else { 
     debugPrint("Not available") 
    } 
} 

// MARK: - SFSafariViewControllerDelegate 

@available(iOS 9.0, *) 

func safariViewControllerDidFinish(controller: SFSafariViewController) 
{ 

    controller.dismissViewControllerAnimated(true, completion: nil) 

} 

首次進口: 進口SafariServices

注:此功能可從的iOS 9.0和沒有Google SDK。

+0

我已經嘗試過上面的代碼,但沒有爲我工作。 我在iOS 11中運行代碼。 – 2017-10-12 06:47:30