[英]How to redirect to iphone app from facebook login
In my iphone app redirect to facebook login like facebook app when clicking a button. 在我的iphone应用程序中,当点击按钮时,重定向到facebook登录,如facebook app。 After login again redirect to my app.
登录后再次重定向到我的应用程序。
i'm using this code 我正在使用此代码
NSArray *permissions =
[NSArray arrayWithObjects:@"user_photos", @"friends_photos",@"email", nil];
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
if(!error)
{
NSLog(@" hi im sucessfully lloged in");
}
}];
in your you AppDelegate modify the method 在你的AppDelegate修改方法
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
NSString *urlString = [url absoluteString];
if ([urlString hasPrefix:@"fb://xxxxxxxxxxxx"]) {
[FBSession.activeSession handleOpenURL:url];
returnValue = YES;
}
return returnValue;
}
also 也
But keep in mind that this is not triggered in IOS 6.In ios 6 the following method will be triggered. 但请记住,这不是在IOS 6中触发的。在ios 6中将触发以下方法。
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [FBSession.activeSession handleOpenURL:url];
}
If the state of your session changes due to login or disconnect FBsession calls the following method and you should handle your cases. 如果会话状态因登录或断开而发生更改FBsession将调用以下方法,您应该处理您的案例。
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState)state
error:(NSError *)error {
switch (state) {
case FBSessionStateOpen: {
//update permissionsArrat
[self retrieveUSerPermissions];
if (!needstoReopenOldSession) {
//First User information
[self getUserInformation:nil];
}
NSNotification *authorizationNotification = [NSNotification notificationWithName:facebookAuthorizationNotification object:nil];
[[NSNotificationCenter defaultCenter] postNotification:authorizationNotification];
}
case FBSessionStateClosed: {
break;
}
case FBSessionStateClosedLoginFailed: {
[FBSession.activeSession closeAndClearTokenInformation];
break;
}
default:
break;
}
if (error) {
NSNotification *authorizationNotification = [NSNotification notificationWithName:faceBookErrorOccuredNotification object:nil];
[[NSNotificationCenter defaultCenter] postNotification:authorizationNotification];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.