requestAccessToAccountsWithType is deprecated in ios6.1, what should i use instead?

2k views Asked by At

-(void)getTwittersFollowers{ ACAccountStore *store=[[ACAccountStore alloc]init]; ACAccountType *twitterAccType=[store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

**[store requestAccessToAccountsWithType:twitterAccType withCompletionHandler:^(BOOL granted,NSError *error)**{
    if(!granted){
        NSLog(@"User refused to access to his account");
    }else{

        NSArray *twitterAcc=[store accountsWithAccountType:twitterAccType];

        if([twitterAcc count]>0){
            ACAccount *account=[twitterAcc objectAtIndex:0];
            NSLog(@"account name %@",[account accountDescription]);

            NSMutableDictionary *params=[[NSMutableDictionary alloc]init];
            [params setObject:@"1" forKey:@"inclue_entitles"];

            NSURL *url=[NSURL URLWithString:@"http://api.twitter.com/1/followers.json"];
            //TWRequest *request=[[TWRequest alloc]initWithURL:url parameters:params requestMethod:TWRequestMethodGET];
            SLRequest *request=[SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:url parameters:params];
            [request setAccount:account];
            [request performRequestWithHandler:^(NSData *responce,NSHTTPURLResponse *urlResponce,NSError *error){
                if(!responce){
                    NSLog(@"%@",error);
                }else{
                    NSError *jsonError;
                    NSMutableDictionary *followers=[NSJSONSerialization JSONObjectWithData:responce options:NSJSONReadingMutableLeaves error:&error];

                        if(followers!=nil){
                            for (int i=0; i<[[followers objectForKey:@"users"] count]; i++) {
                                NSLog(@"_____%@",[[[followers objectForKey:@"users"] objectAtIndex:i] objectForKey:@"screen_name"]);
                                NSLog(@"______________________________________%@",[[[followers objectForKey:@"users"] objectAtIndex:i] objectForKey:@"profile_image_url"]);


                                [nameArray addObject:[[[followers objectForKey:@"users"] objectAtIndex:i] objectForKey:@"screen_name"]];


                                NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[[followers objectForKey:@"users"] objectAtIndex:i] objectForKey:@"profile_image_url"]]];


                                [imageArray addObject:imageData];

                                NSLog(@"%i", [imageArray count]);
                            }

                        }else{
                            NSLog(@"%@",jsonError);
                        }


                }
            }];
        }
    }


}];

}

what should i use instead of highlighted code...?

1

There are 1 answers

7
JustSid On BEST ANSWER

Though it's for some reason not explicitly mentioned in the documentation, the replacement for the method is - (void)requestAccessToAccountsWithType:(ACAccountType *)accountType options:(NSDictionary *)options completion:(ACAccountStoreRequestAccessCompletionHandler)completion (which can easily be found out by looking at the documentation)