我正在使用ShareKit在Facebook上分享一个简单的文字 . 我使用cocoapods在我的应用程序上安装ShareKit(使用iOS7和XCode5),然后按照配置教程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确认对话框中,并提出上述问题 . 这个循环永远循环 .
你知道我错过了什么吗?谢谢
1 回答
哦,我现在看到 - 如果你喜欢直接打电话给sharer,而不是打电话
SHKFacebook和SHKiOSFacebook之间的区别在于前者使用Facebook iOS SDK,而后者使用Accounts.framework和Social.framework .