share on Facebook
I am using ShareKit to share a simple text on Facebook. I use cocoapods to install ShareKit on my application (with iOS7, and XCode5), and follow the configuration tutorial ConfigurationShareKit. More specifically, I do the following things:
1) Write the URL Scheme into the plist.
2) Create a DefaultSHKConfigurator sub-class:
@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) Make the initial configuration in the 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) Share on 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]; }
Now, What result I got on the real device is a facebook confirm dialog with question: "You have already authorized MyApp". After I push OK button, it comes back to the share dialog. And after I push the "Send To Facebook", it once again comes back to the Facebook confirm dialog with the above question. This cycle loops forever.
Do you know what did I miss? Thanks
Oh I see now - if you prefer to call sharer directly, than call
[SHKiOSFacebook shareItem:item];
The difference between SHKFacebook and SHKiOSFacebook is that the former uses Facebook iOS SDK, while the latter uses Accounts.framework and Social.framework.
链接地址: http://www.djcxy.com/p/35474.html上一篇: Graph API无法将提要发布到Facebook页面
下一篇: 在脸书上分享