0

我遇到了这个问题,我正在使用 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];
4

1 回答 1

0

您可以非常轻松地禁用 iOS 上的空闲计时器 - 请参阅此问题:

如何在 iOS 中以编程方式禁用/启用睡眠模式?

尽管这应该可以解决您的问题,但请确保您没有在主线程上进行网络操作。我无法从您发布的堆栈跟踪中看出,但我怀疑您可能是。正如其他人已经建议的那样,ASIHTTPRequest如果可能,您应该迁移到更现代的替代方案。

于 2013-08-30T21:56:54.010 回答