简体   繁体   中英

In facebook ios6 not entering in to the if(granted ) loop "Sign in with Facebook"

Hi I am working "Sign in with facebook", My code is below Here not entering in to the if(granted ) loop. After i clicked the "ok" in pop up the console is printing like below 2 012-11-28 15:47:08.558 Tattoo Later[2748:1d34b] type:com.apple.facebook identifier: B962F897-6BAE-4769-8C04-B1B3D2C872A2 accountDescription: Facebook username: example@yahoo.co.in objectID: x-coredata://EBF41CAD-7388-45E0-8621-3958C7A67491/Account/p1 enabledDataclasses: {( "com.apple.Dataclass.Contacts", "com.apple.Dataclass.Calendars" )} enableAndSyncableDataclasses: {( )} properties: { fullname = "Example"; uid = 100001462475956; } parentAccount: (null) owningBundleID:(null) 012-11-28 15:47:08.558 Tattoo Later[2748:1d34b] type:com.apple.facebook identifier: B962F897-6BAE-4769-8C04-B1B3D2C872A2 accountDescription: Facebook username: example@yahoo.co.in objectID: x-coredata://EBF41CAD-7388-45E0-8621-3958C7A67491/Account/p1 enabledDataclasses: {( "com.apple.Dataclass.Contacts", "com.apple.Dataclass.Calendars" )} enableAndSyncableDataclasses: {( )} properties: { fullname = "Example"; uid = 100001462475956; } parentAccount: (null) owningBundleID:(null)

My Code when we click "Sign in with Facebook":

-(IBAction)loginWithFacebookClicked:(id)sender
{
 ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSArray * permissions = [NSArray arrayWithObjects:@"email",@"user_location", nil];
        NSDictionary * dict=[NSDictionary dictionaryWithObjectsAndKeys:@"238864112907671",ACFacebookAppIdKey,permissions,ACFacebookPermissionsKey,ACFacebookAudienceEveryone,ACFacebookAudienceKey, nil];
[accountStore requestAccessToAccountsWithType:accountType options:dict completion:^(BOOL granted, NSError *error) {
            if(granted ) {
                NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
if ([accountsArray count] > 0) {
ACAccount *fbAccount = [accountsArray objectAtIndex:0];
                    NSLog(@"%@",fbAccount);
}
            }
            else
            {
                NSLog(@"%@",[error localizedDescription]);
            }
        }];
}

Initially i got some errors like

The Facebook server could not fulfill this access request: The proxied app cannot request publish permissions without having being installed previously.

Error Domain=com.apple.accounts Code=7 "The Facebook server could not fulfill this access request: invalid app id" UserInfo=0xa29f520 {NSLocalizedDescription=The Facebook server could not fulfill this access request: invalid app id}

Later i solved by searching but i did not get solution for this

Please guide me Thanks in advance

The answer is very simple! The completion block is called on arbitrary thread LATER. So if you going step by step it actually exits your method and continue work on main thread and later when you get response it enters either if or else section. Your log is actually proving that you've entered if section (it logs account). If you place a break point in if section you'll notice this behavior. So your code is ok.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM