[英]ShareKit - share on Facebook
我正在使用ShareKit在Facebook上共享一個簡單的文本。 我使用cocoapods在我的應用程序(與iOS7和XCode5)上安裝ShareKit,並按照配置教程ConfigurationShareKit進行操作 。 更具體地說,我執行以下操作:
1)將URL Scheme寫入plist。
2)創建一個DefaultSHKConfigurator子類:
@interface MySHKConfigurator : DefaultSHKConfigurator @end @implementation MySHKConfigurator - (NSString*)facebookAppId { return @"xxx"; } -(NSString *)appName { return @"MyAppName"; } - (NSArray*)facebookWritePermissions { return [NSArray arrayWithObjects:@"publish_actions",@"publish_stream", nil]; //@"offline_access", } - (NSArray*)facebookReadPermissions { return nil; // this is the defaul value for the SDK and will afford basic read permissions } @end
3)在AppDelegate中進行初始配置:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. DefaultSHKConfigurator *configurator = [[MySHKConfigurator alloc] init]; [SHKConfiguration sharedInstanceWithConfigurator:configurator]; //[SHK flushOfflineQueue]; return YES; } - (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. [SHKFacebook handleDidBecomeActive]; } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. // Save data if appropriate [SHKFacebook handleWillTerminate]; } - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { NSString* scheme = [url scheme]; if ([scheme hasPrefix:[NSString stringWithFormat:@"fb%@", SHKCONFIG(facebookAppId)]]) { return [SHKFacebook handleOpenURL:url]; } return YES; }
4)在Facebook上分享
- (IBAction)shareFacebook:(id)sender { //- The url should be a link to your app on the app store NSURL *url = [NSURL URLWithString:@"http://www.google.com"]; //- Share on Facebook SHKItem *item = [SHKItem URL:url title:self.textView.text contentType:SHKURLContentTypeWebpage]; [SHKFacebook shareItem:item]; }
現在,我在真實設備上得到的結果是一個帶有問題的Facebook確認對話框:“您已經授權MyApp”。 按“確定”按鈕后,它返回到共享對話框。 然后,當我按下“發送到Facebook”后,它再次返回到帶有上述問題的Facebook確認對話框。 這個循環永遠循環。
你知道我想念什么嗎? 謝謝
哦,我現在知道了-如果您希望直接致電共享者,而不是致電
[SHKiOSFacebook shareItem:item];
SHKFacebook和SHKiOSFacebook之間的區別在於,前者使用Facebook iOS SDK,而后者使用Accounts.framework和Social.framework。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.