gpt4 book ai didi

iOS 应用程序在存档后表现不同

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

直接从手机上的 xcode 运行应用程序时,一切运行良好。将其存档并将其作为存档运行后,该应用程序的行为会有所不同并且不会按预期运行。这是从存档运行时 asihttprequest 永远不会结束的部分。我很乐意提供一些帮助。

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];

[tracker sendEventWithCategory:@"uiAction"
withAction:@"station pressed"
withLabel:@"Station number"
withValue:num];

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://server.com/servlet?stationId=%d", [num intValue]]];

__weak ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
NSLog(@"0");

[request setCompletionBlock:^{
@try {
NSLog(@"1");
StopParser *stop = [[StopParser alloc]init];
NSLog(@"2");
timesArray = [stop getStationsListfromString:[request responseString]];
NSLog(@"3");
[stView.downlodingLabel setHidden:YES];
[stView.downloadingIndicator setHidden:YES];
[stView.tableview reloadData];
[stView.tableview setHidden:NO];


}
@catch (NSException *exception) {
NSLog(@"4");
[stView.downloadingIndicator setHidden:YES];
[stView.downlodingLabel setHidden:NO];
[stView.downlodingLabel setText:@"נא לנסות מאוחר יותר"];
[stView.tableview setHidden:YES];

}
@finally {
[refreshControl endRefreshing];
}

}];
[request setFailedBlock:^{
NSLog(@"5");
[stView.downloadingIndicator setHidden:YES];
[stView.downlodingLabel setHidden:NO];
[stView.downlodingLabel setText:@"נא לנסות מאוחר יותר"];
[stView.tableview setHidden:YES];
[refreshControl endRefreshing];

}];
[request startAsynchronous];

最佳答案

我认为 __weak 是你的问题。请改用 __block

没有为request保存强引用,所以释放。

ARC Introduces New Lifetime Qualifiers

  • __weak 指定一个引用,该引用不会使引用的对象保持事件状态。当没有对对象的强引用时,弱引用设置为 nil。

The __block Storage Type

__block 变量存在于变量的词法范围和在变量的词法范围内声明或创建的所有 block 和 block 副本之间共享的存储中。因此,如果在帧内声明的 block 的任何副本在帧结束后仍然存在(例如,通过在某处排队以供稍后执行),则存储将在堆栈帧的破坏中幸存下来。给定词法范围内的多个 block 可以同时使用共享变量。


更新

明确我的建议是替换:

__weak ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];

与:

__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];

这不应导致保留周期。

关于iOS 应用程序在存档后表现不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16172303/

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