• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

iphone - EXC_BAD_ACCESS -iPhone objective-c

[复制链接]
菜鸟教程小白 发表于 2022-12-13 15:09:10 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我一直在尝试这个 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,但它仍然崩溃...



Best Answer-推荐答案


在您的 block 中,您会查找错误,但如果您遇到错误,请记录并继续。你应该写一个“else”语句,只有在没有错误的情况下才继续。

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

另外,我怀疑 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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap