在脸书上分享

我正在使用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”。 按下OK按钮后,它返回共享对话框。 在我推送“发送到Facebook”后,它再一次返回到带有上述问题的Facebook确认对话框。 这个循环永远循环。

你知道我错过了什么吗? 谢谢


哦,我现在看到 - 如果你更愿意直接打电话给分享者,而不是打电话

[SHKiOSFacebook shareItem:item];

SHKFacebook和SHKiOSFacebook的区别在于前者使用Facebook iOS SDK,而后者使用Accounts.framework和Social.framework。

链接地址: http://www.djcxy.com/p/35473.html

上一篇: share on Facebook

下一篇: The developers of this app have not set up this app properly for Facebook Login?