前言
Google Plus的分享功能要加到iOS專案裡面不會太困難.
官方網站的原文教學
環境設定
下載Google+ iOS SDK (official link)
檢查一下
AssetsLibrary.framework
Foundation.framework
CoreLocation.framework
CoreMotion.framework
CoreGraphics.framework
CoreText.framework
MediaPlayer.framework
Security.framework
SystemConfiguration.framework
UIKit.framework
並從下載回來的Google+ iOS SDK資料夾內
拖曳&import
GooglePlus.framework
GoogleOpenSource.framework
建立一個API project
1. 前往Google API Console
舊版的設定頁面
註冊一個app
完成後應該長得像這樣
新版的設定頁面
啟用Google+API
註冊一個app
填寫必要資訊
完成後應該長得像這樣
程式
在AppDelegate.m #import#import static NSString * const kClientID = @"blahblahblah.apps.googleusercontent.com"; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Set app's client ID for |GPPSignIn| and |GPPShare|. [GPPSignIn sharedInstance].clientID = kClientID; ... }
在ViewController.m
@interface YourViewController (){ ... - (void)viewDidLoad { [super viewDidLoad]; [GPPShare sharedInstance].delegate = self; } ... - (void)gplusBtnPressed:(id)sender { id shareBuilder = [[GPPShare sharedInstance] shareDialog]; // This line will fill out the title, description, and thumbnail of the item // you're sharing based on the URL you included. //[shareBuilder setURLToShare:[NSURL URLWithString:@"The url you want to share"]]; [shareBuilder setContentDeepLinkID:@"DeepLinkID"]; [shareBuilder setTitle:@" 標題 " description:@" 描述"] thumbnailURL:[NSURL URLWithString:[@"縮圖網址"]]]; [shareBuilder setPrefillText:msg]; [shareBuilder open]; } #pragma mark - GPPShareDelegate - (void)finishedSharing:(BOOL)shared { } - (void)reportAuthStatus { if ([GPPSignIn sharedInstance].authentication) { NSLog(@"Status: Authenticated"); } else { // To authenticate, use Google+ sign-in button. NSLog(@"Status: Not authenticated"); } }
如果分享時發生Error 404 Not Found, 那最有可能就是client ID沒有符合
希望大家都分享順利囉~
Sent from Evernote |
沒有留言:
張貼留言