【发布时间】:2015-02-12 10:19:27
【问题描述】:
我想在 Objetive-C 中创建一个动作,在 Twitter 帐户中立即“关注”,但是当我启动我的应用程序时它崩溃了。谁能告诉我怎么了?
它返回thread 1 exc_bad_access。
- (IBAction)Twitter:(id)sender {
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil
completion:^(BOOL granted, NSError *error) {
if(granted) {
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
if ([accountsArray count] > 0) {
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
[tempDict setValue:@"user" forKey:@"UserName"];
[tempDict setValue:@"true" forKey:@"follow"];
NSURL *URLTwitter = [NSURL URLWithString:@"https://api.twitter.com/1.1/friendships/create.format"];
SLRequest *postRequest = [SLRequest requestForServiceType:@"Twitter" requestMethod:SLRequestMethodPOST URL:URLTwitter parameters:tempDict];
[postRequest setAccount:twitterAccount];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *output = [NSString stringWithFormat:@"HTTP response status: %li", [urlResponse statusCode]];
NSLog(@"%@", output);
}];
}
}
}];
}
【问题讨论】:
-
什么是崩溃堆栈?
-
返回
thread 1 exc_bad_access -
你需要在调试器中运行它。当它崩溃时,在调试器控制台中输入
bt并将输出粘贴到此处。 -
作为旁注......您使用
[tempDict setValue:@"user" forKey:@"UserName"];而不是tempDict[@"user"] = @"UserName"的任何原因? -
@AshleyMills 我认为是一样的,不是吗?
标签: ios objective-c twitter