2
votes

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

1
Any particular reason you are not using accounts framework?Swapnil Luktuke
What do you mean by accounts framework? Can you tell me more in details? I only know that the ShareKit is the best library to share on multiple social networks. No?chipbk10
I did spend some time on ShareKit, so I do not want to switch to another. Because I do not know that with the Accounts Framework, I do not get the same error.chipbk10
You may want to look at UIActivityViewController as well, personally not a fan of share kit.Gapp
It seems that for whatever reason ShareKit is using SHKFacebook, instead of modern SHKiOSFacebook (which should use Accounts.framework). SHKFacebook is historically not perfect, and by accident I am rewriting it at the moment, and I have encountered that cycling bug too. Should be fixed soon. However, you should preferably use SHKiOSFacebook sharer. Do you have custom Sharers.plist? This might be the cause ShareKit fails back to old SHKFacebook sharer.Vilém Kurz

1 Answers

4
votes

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.