我正在使用我的应用程序中的Facebook SDK登录控件,只要用户在iOS的设置部分配置了他的Facebook帐户,它的工作正常。
问题是没有配置帐户报告无法登录的用户。
为了测试问题,我删除了我的帐户,确实 - 尝试登录时,我看到该应用程序正在打开Facebook应用程序/浏览器并立即将其关闭并返回登录屏幕。
是否有针对登录控件的特殊配置或实现登录的替代方法,以便它支持所有用户?
我的代码:
FBLoginView *loginView = [[FBLoginView alloc] init];
loginView.delegate=self;
loginView.readPermissions = @[@"basic_info", @"email"];
loginView.defaultAudience=FBSessionDefaultAudienceEveryone;
loginView.frame = CGRectOffset(loginView.frame, (self.view.center.x - (loginView.frame.size.width / 2)), 270);
[self.view addSubview:loginView];
添加以下代码到appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FBLoginView class];
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.
[[FBSession activeSession] handleDidBecomeActive];
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
[[FBSession activeSession] close];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// Call FBAppCall's handleOpenURL:sourceApplication to handle Facebook app responses
BOOL wasHandled = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
// You can add your app-specific url handling code here if needed
return wasHandled;
}