【问题标题】:ASIHTTPRequest Cache is crashing appASIHTTPRequest 缓存使应用程序崩溃
【发布时间】:2023-03-14 19:48:01
【问题描述】:

我有以下代码:

+ (NSMutableArray*)getTodayData:(NSDate*)today
{
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/ichrono/20110715/60b88126/load_dr_daily_schedule/%@/", [self getDrChronoHost], [dateFormat stringFromDate:today]]];

        ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
        [self addCurrentUserLoginToPostRequest:request];        
        [request setPostValue:[dateFormat stringFromDate:today] forKey:@"target_date"];
        [request setDownloadCache:[ASIDownloadCache sharedCache]];
        [request startSynchronous];

        NSError *error = [request error];
        NSString *responseString;
        if (!error) {
            responseString = [request responseString];
        } else {
            return NULL;
        }
        return [responseString JSONValue];
    }
}

在我添加[request setDownloadCache:[ASIDownloadCache sharedCache]]; 之前它运行良好。

我如何得到错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ASIFormDataRequest setDownloadCache:]: unrecognized selector sent to instance 0x9a0140'

【问题讨论】:

    标签: iphone objective-c cocoa-touch asihttprequest


    【解决方案1】:

    因为setDownloadCache 不是ASIFormDataRequest 中定义的实例方法。

    根据ASIHTTPRequest 文档: http://allseeing-i.com/ASIHTTPRequest/How-to-use#using_a_download_cache

    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setDownloadCache:[ASIDownloadCache sharedCache]];
    

    你的例外说明了一切“'-[ASIFormDataRequest setDownloadCache:]: unrecognized selector sent to instance 0x9a0140

    【讨论】:

    • 那么我是否可以使用 ASIFormDataRequest 设置缓存?
    • 那么我有什么替代方法来存储数据?它也被 JSON 解析。
    • [ASIHTTPRequest setDefaultCache:[ASIDownloadCache sharedCache]];添加上述行可能会有所帮助。我不熟悉 ASIHTTPRequest。以前从未使用过此 API。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-10
    • 2012-08-18
    • 2012-02-12
    • 2014-03-18
    • 2014-11-14
    相关资源
    最近更新 更多