0

I have written this code:

self.accountStore = [[ACAccountStore alloc]init];
ACAccountType *FBaccountType= [self.accountStore accountTypeWithAccountTypeIdentifier:
     ACAccountTypeIdentifierFacebook];
NSString *key = @"987654"; //put your own key from FB here
NSDictionary *dictFB = //use ACAccountStore to help create your dictionary

[self.accountStore requestAccessToAccountsWithType:FBaccountType
                                           options:dictFB
                                        completion: ^(BOOL granted, NSError *e) {
                                                if (granted)
                                                {
                                                    NSArray *accounts = [self.accountStore accountsWithAccountType:FBaccountType];
                                                    //it will always be the last object with SSO
                                                    self.facebookAccount = [accounts lastObject];
                                                }
                                                else
                                                {
                                                    //Fail gracefully...
                                                    NSLog(@"error getting permission %@",e);
                                                }
                                            }];

NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                        requestMethod:SLRequestMethodGET
                                                  URL:requestURL
                                           parameters:nil];

request.account = self.facebookAccount;
[request performRequestWithHandler:^(NSData *data,
                                     NSHTTPURLResponse *response,
                                     NSError *error) {
                                         if(!error)
                                         {
                                             NSDictionary *list =[NSJSONSerialization JSONObjectWithData:data
                                                                               options:kNilOptions error:&error];

                                             NSLog(@"Dictionary contains: %@", list );
                                         }
                                         else
                                         {
                                             //handle error gracefully
                                         }                     
                                     }];


-(void)accountChanged:(NSNotification *)notif//no user info associated with this notif
{
    [self attemptRenewCredentials];
}


-(void)attemptRenewCredentials
{
    [self.accountStore renewCredentialsForAccount:(ACAccount *)self.facebookAccount
                                       completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) {
                                           if(!error)
                                           {
                                              switch (renewResult)
                                              {
                                                  case ACAccountCredentialRenewResultRenewed:
                                                      NSLog(@"Good to go");
                                                      [self get];
                                                      break;
                                                  case ACAccountCredentialRenewResultRejected:
                                                      NSLog(@"User declined permission");
                                                      break;
                                                  case ACAccountCredentialRenewResultFailed:
                                                      NSLog(@"non-user-initiated cancel, you may attempt to retry");
                                                      break;
                                                  default:
                                                      break;
                                              }

                                         }
                                         else
                                         {
                                             //handle error gracefully
                                             NSLog(@"error from renew credentials%@",error);
                                         }
                                     }];
}

It works great on iPhone simulator (iOS 6) but it dosent work on my iPhone (iOS 6). It dosen't show the SLComposeViewController.

4

0 回答 0