繁体   English   中英

ShareKit-在Facebook上分享

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM