iOS Social和Accounts简单使用

    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);

                    }

                }];

            }

        }

    }];

posted @ 2017-07-15 11:06  码码码  阅读(324)  评论(0编辑  收藏  举报