gpt4 book ai didi

iphone - EXC_BAD_ACCESS -iPhone objective-c

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:14:33 25 4
gpt4 key购买 nike

我一直在尝试这个 Twitter api 的东西,它真的很令人困惑......

使用以下代码时,我一直收到 EXC_BAD_ACCESS 错误访问...这里有什么问题?

NSURL *followingURL = [NSURL URLWithString:@"https://api.twitter.com/1/users/lookup.json"];
// Pass in the parameters (basically '.ids.json?screen_name=[screen_name]')
id fromIntToNum = [NSNumber numberWithInteger: friID];
NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:@"159462573", @"user_id", nil];
// Setup the request
twitterRequest = [[TWRequest alloc] initWithURL:followingURL
parameters:parameters
requestMethod:TWRequestMethodGET];
// This is important! Set the account for the request so we can do an authenticated request. Without this you cannot get the followers for private accounts and Twitter may also return an error if you're doing too many requests
[twitterRequest setAccount:theAccount];
// Perform the request for Twitter friends
[twitterRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if (error) {
/*
// deal with any errors - keep in mind, though you may receive a valid response that contains an error, so you may want to look at the response and ensure no 'error:' key is present in the dictionary
NSLog(@"%@",error);*/
} else {
/*NSError *jsonError = nil;
// Convert the response into a dictionary
NSDictionary *twitterGrabbedUserInfo = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONWritingPrettyPrinted error:&jsonError];
// Grab the Ids that Twitter returned and add them to the dictionary we created earlier
NSLog(@"%@", [twitterGrabbedUserInfo objectForKey:@"screen_name"]);*/
}

}];

我分隔了我的代码失败的那一行...

是什么导致了这个 Twitter API 问题?

以下行导致崩溃:::

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

我有时也会遇到这个错误:

[__NSCFNumber credentialForAccount:]: unrecognized 

更新:我注释掉了处理程序并制作了 TwitterRequest 和 ivar,但它仍然崩溃...

最佳答案

在你的 block 中你寻找一个错误,但如果你得到一个你记录它并继续。您应该放入一个“else”语句,只有在没有错误的情况下才继续。

为什么不尝试注释掉处理程序中的所有代码 - 不要做任何事情 - 看看是否会崩溃。然后尝试仅使用错误代码。然后尝试使用 JSON 序列化,最后一行。如果您能找到导致问题的 block 部分,那将会有所帮助。

此外,我怀疑 performRequestWithHandler: 不会阻塞,但希望您在 block 内通知您的类请求已完成。如果是这样,则意味着“TWRequest *twitterRequest”应该是一个 ivar 或属性,并且您需要允许在处理程序完成时调用某些方法。您的崩溃可能是由于 ARC 在对象运行时重新分配了您的对象。

编辑:请注意,TWRequest 类描述中说:“使用 initWithURL:parameters:requestMethod: 方法来初始化传递所需属性值的新创建的 TWRequest 对象。”它说的是 PLURAL 属性,表示大于 1。难道它也期望“credentialForAccount”属性?您必须阅读 Twitter 文档才能找到所有必需的属性。

编辑2:好吧,我们甚至不知道您是否已经达到处理程序的程度。在那里放一个 NSLog 但我怀疑它永远不会那么远。如果为真,则留下三种可能性:

a) 它不喜欢这个 URL(虽然这看起来不错)

b) 你缺少它期望的一些参数

c) id 不喜欢“theAccount”对象——它是一个有效的 ACAccount 对象吗?试试 NSLogging 吧。

它必须是这三件事之一。

关于iphone - EXC_BAD_ACCESS -iPhone objective-c ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11633026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com