1. 程式人生 > >iOS Social和Accounts簡單使用

iOS Social和Accounts簡單使用

count mon sed type eid httpurl orm ice sin

ACAccountStore *account = [[ACAccountStore alloc] init];

ACAccountType *type = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierSinaWeibo];

[account requestAccessToAccountsWithType:type options:nil completion:^(BOOL granted, NSError *error) {

if (granted)

{

NSArray *array = [account accountsWithAccountType:type];

NSLog(@"賬號%@",array);

if (array.count > 0)

{

SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeSinaWeibo requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:@"https://api.weibo.com/2/common/get_city.json"] parameters:[NSDictionary dictionaryWithObject:@"001011" forKey:@"province"]];

request.account = [array objectAtIndex:0];

[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {

//NSLog(@" == %@",responseData);

NSError *errorr = nil;

NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&errorr];

if (!error)

{

NSLog(@"北京區 %@",dic);

}

}];

}

}

}];

iOS Social和Accounts簡單使用