我遇到了这个问题,我正在向ASIHttpRequest发出请求需要几分钟,当请求完成时,iPad处于低功耗状态,屏幕显示为黑色等。下载的数据保存在coredata中在这个过程中应用程序崩溃。
这是崩溃信息的一部分:
MyApp[2978] has active assertions beyond permitted time:
{(
<BKProcessAssertion: 0x1f841ec0> identifier: Suspending process: MyApp[2978] permittedBackgroundDuration: 10.000000 reason: suspend owner pid:26 preventSuspend preventThrottleDownCPU preventThrottleDownUI
)}
Elapsed total CPU time (seconds): 10.220 (user 10.220, system 0.000), 51% CPU
Elapsed application CPU time (seconds): 9.860, 49% CPU
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0:
0 libsystem_kernel.dylib 0x3c6ae39c pread + 20
1 libsqlite3.dylib 0x3c3b75c8 0x3c3b2000 + 21960
2 libsqlite3.dylib 0x3c3ca0fe 0x3c3b2000 + 98558
3 libsqlite3.dylib 0x3c3c929a 0x3c3b2000 + 94874
4 libsqlite3.dylib 0x3c3e208e 0x3c3b2000 + 196750
5 libsqlite3.dylib 0x3c3e32be 0x3c3b2000 + 201406
6 libsqlite3.dylib 0x3c3df488 0x3c3b2000 + 185480
7 libsqlite3.dylib 0x3c3d8482 sqlite3_step + 2138
8 CoreData 0x340e596a _execute + 122
9 CoreData 0x340e5864 -[NSSQLiteConnection execute] + 2168
10 CoreData 0x341a5486 newFetchedRowsForFetchPlan_MT + 1006
11 CoreData 0x340ec73a -[NSSQLCore objectsForFetchRequest:inContext:] + 678
12 CoreData 0x340ec200 -[NSSQLCore executeRequest:withContext:error:] + 464
13 CoreData 0x340eb618 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 1640
14 CoreData 0x340e9f12 -[NSManagedObjectContext executeFetchRequest:error:] + 642
15 Georeporting 0x000b7506 +[Model loadObject:withId:createNew:] (ModelObject.m:51)
16 Georeporting 0x000b18ae -[Data request:didFinished:] (DataManager.m:309)
17 Georeporting 0x000a69fe -[Server requestFinished:] (ServerClient.m:80)
18 Georeporting 0x000e6c04 -[ASIHTTPRequest reportFinished] + 76
这是executeFetchRequest
的代码NSEntityDescription * entity = [NSEntityDescription entityForName:[objectClass entityName] inManagedObjectContext:[Model manageObjectContext]];
NSFetchRequest * fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:entity];
NSString * query = [NSString stringWithFormat:@"%@='%@'", [objectClass primaryKeyFieldName], objectKey];
NSPredicate * predicate = [NSPredicate predicateWithFormat:query];
[fetchRequest setPredicate:predicate];
NSArray * objects = [[ModelObject manageObjectContext] executeFetchRequest:fetchRequest error:nil];
答案 0 :(得分:0)
您可以非常轻松地在iOS上禁用空闲计时器 - 请参阅此问题:
How to disable/enable the sleep mode programmatically in iOS?
虽然这应该可以解决您的问题,但请确保您没有在主线程上进行网络操作。我无法从你发布的堆栈跟踪中看出来,但我怀疑你可能是。正如其他人已经建议的那样,如果可能,您应该从ASIHTTPRequest
迁移到更现代的替代方案。