[英]Open facebook dialog for authentication instead of Installed facebook app in iphone?
我想制作一個要求對對話框中的Facebook登錄進行身份驗證的應用程序,無論是在iPhone中安裝了Facebook應用程序,還是未安裝。如果我注銷了Facebook,則應該從Facebook中注銷。 我已經將facebook-ios-sdk用於facebook api,我的代碼如下:
- (void)viewDidLoad
{
_facebook=[[Facebook alloc] initWithAppId:appId andDelegate:self];
self.navigationController.navigationBarHidden = YES;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"])
{
_facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
_facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
[super viewDidLoad];
}
//點擊登錄按鈕
-(IBAction)Login
{
NSLog(@"login called");
if (![self connected])
{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Connection" message:@"Internet is not Connected" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];[alert release];
}
else
{
if (suggestion==nil)
{
suggestion=[[Suggestions alloc] initWithNibName:@"Suggestions" bundle:nil];
}
[suggestion setReqFlg:YES];
if (![_facebook isSessionValid])
{
NSLog(@"sesssion invalid u have to login...");
[_facebook authorize:nil];
}
else
{
NSLog(@"valid and going on next page called graph API ");
[_facebook requestWithGraphPath:@"me?fields=id,name" andDelegate:self];
suggestion.parentView=self;
[self.navigationController pushViewController:suggestion animated:YES];
}
}
}
- (void)fbDidLogin
{
NSLog(@"facebook did first login..");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[_facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[_facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
NSLog(@"called gtraph from login in facebook ");
[_facebook requestWithGraphPath:@"me?fields=id" andDelegate:self];
if (suggestion==nil)
{
suggestion=[[Suggestions alloc] initWithNibName:@"Suggestions" bundle:nil];
}
suggestion.parentView=self;
[self.navigationController pushViewController:suggestion animated:YES];
}
- (void)fbDidLogout
{
NSLog(@"logout");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults removeObjectForKey:@"FBAccessTokenKey"];
[defaults removeObjectForKey:@"FBExpirationDateKey"];
[defaults removeObjectForKey:@"FBUserId"];
[defaults synchronize];
}
我是否需要在facebook.m文件中進行更改還是有另一種方法?每次我都單擊登錄按鈕時,如果Facebook已注銷,則應顯示Facebook登錄對話框;如果Facebook已登錄,則導航至下一個視圖。請勿打開Facebook應用程序安裝在iPhone中用於登錄目的。
給我您真正需要的評論或答案。 謝謝你!
它非常簡單,進入facebook.m文件,使用FBAppAuth搜索,您將獲得3_4的結果,例如:
[self authorizeWithFBAppAuth:YES safariAuth:YES];
只需將YES更改為NO即可:-
[self authorizeWithFBAppAuth:NO safariAuth:NO];
僅在facebook.m中更改它,然后編譯並運行,當您單擊loginButton時出現fblogin對話框:)
編輯
我的應用程序登錄頁面上顯示了登錄對話框
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.