请求发送获取错误:[CFString release]:消息发送到已释放的实例 0x6a83e00

发布于 2024-12-11 03:33:40 字数 1655 浏览 0 评论 0原文

我想检查苹果的应用程序版本,因此我

- (void)connectToCheckVersion{
NSString *url = @"http://itunes.apple.com/lookup?id=466424846";
TTURLRequest *_request = [TTURLRequest requestWithURL:url delegate:self];
_request.httpMethod = @"GET";
_request.cachePolicy = TTURLRequestCachePolicyNone;
_request.shouldHandleCookies = NO;
TTURLJSONResponse* response = [[TTURLJSONResponse alloc] init];
_request.response = response;
TT_RELEASE_SAFELY(response); 
[_request send];
}


- (void)requestDidFinishLoad:(TTURLRequest*)request {
    TTURLJSONResponse* response = request.response;
    NSDictionary* json = response.rootObject;

    NSArray *results = [json objectForKey:@"results"];
    NSString *version;
    for (NSDictionary *rawResult in results) {

        version = [rawResult objectForKey:@"version"];
    }
    NSString *currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
    if (version != nil && currentVersion != nil && ![version isEqualToString:currentVersion]) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"info" 
                                                        message:@"newer version" 
                                                       delegate:self 
                                              cancelButtonTitle:@"ok"
                                              otherButtonTitles:nil, nil];
        [alert show];
        [alert release];

    }

}

在 [_request send] 之后发送如下请求;将得到 [CFString release]:发送到已释放实例 0x6a83e00 的消息。我检查了此方法中的所有字符串似乎都没有问题,并且我仍然可以从远程获得正确的响应。

如果我注释掉这个 connectToCheckVersion 方法,那么就没有任何问题。 有死吗?

I want to check the app version from apple so I send request like below

- (void)connectToCheckVersion{
NSString *url = @"http://itunes.apple.com/lookup?id=466424846";
TTURLRequest *_request = [TTURLRequest requestWithURL:url delegate:self];
_request.httpMethod = @"GET";
_request.cachePolicy = TTURLRequestCachePolicyNone;
_request.shouldHandleCookies = NO;
TTURLJSONResponse* response = [[TTURLJSONResponse alloc] init];
_request.response = response;
TT_RELEASE_SAFELY(response); 
[_request send];
}


- (void)requestDidFinishLoad:(TTURLRequest*)request {
    TTURLJSONResponse* response = request.response;
    NSDictionary* json = response.rootObject;

    NSArray *results = [json objectForKey:@"results"];
    NSString *version;
    for (NSDictionary *rawResult in results) {

        version = [rawResult objectForKey:@"version"];
    }
    NSString *currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
    if (version != nil && currentVersion != nil && ![version isEqualToString:currentVersion]) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"info" 
                                                        message:@"newer version" 
                                                       delegate:self 
                                              cancelButtonTitle:@"ok"
                                              otherButtonTitles:nil, nil];
        [alert show];
        [alert release];

    }

}

and after [_request send]; will get [CFString release]: message sent to deallocated instance 0x6a83e00. I checked all Strings in this method seems they are ok, and I can still get correct response from remote.

If I comment out this connectToCheckVersion method then no any problem.
Any diea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

じее 2024-12-18 03:33:40

我认为您应该保留 _request 变量并将其保存为成员。
因为函数返回后会自动释放

请求成功或失败后都必须释放它。

谢谢。

I think that you should retain the _request variable and save it as a member.
Because it will autorelease after the function is returned.

You have to release it after the request is successed or failed.

Thank you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文