2013-08-29 150 views
2

- (void)getTwittersFollowers {AC_ccountStore * store = [[ACAccountStore alloc] init]; ACAccountType * twitterAccType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];requestAccessToAccountsWithType在ios6.1中已棄用,我應該用什麼來代替?

**[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); 
         } 


       } 
      }]; 
     } 
    } 


}]; 

}

我應該怎麼改用中突出顯示的代碼......?

回答

8

雖然它是對文檔中沒有明確提及某種原因,更換爲方法是- (void)requestAccessToAccountsWithType:(ACAccountType *)accountType options:(NSDictionary *)options completion:(ACAccountStoreRequestAccessCompletionHandler)completion(其可以容易地通過查看文檔被發現)

+0

[自getTwittersFollowers]; FollowersViewController * friends = [[FollowersViewController alloc] initWithStyle:UITableViewStylePlain]; friends.nameArray = self.nameArray; friends.imageArray = self.imageArray; UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:friends]; [self presentViewController:navigationController animated:YES completion:nil]; – Nitesh

+0

感謝您的回答。我還有一個問題,我已經在按鈕單擊操作上調用了這個方法,就像編譯器調用這個方法,它會進入它的塊並且突然沒有完成它,它會切換回按鈕動作的進一步指令,並彈出下一個視圖控制器,因爲我編碼這將有數據檢索該塊。我在那裏有空桌子。但我看到編譯器正在運行該塊現在.again通過導航的後背btn回來,就像我現在單擊此按鈕它會顯示我的Twitter的追隨者列表。 – Nitesh

+0

@Nitesh該方法是異步的。該方法不能保證在方法返回之前被調用。 – JustSid

相關問題