3

我收到以下崩溃报告,该应用程序在后台与 NSURLconnection 进行后台通信,超时时间为 7 秒:

Incident Identifier: 3C862AC5-4226-461B-ACC8-6F080D2FDFDB
CrashReporter Key:   119b92a02f2002d19cf9f0b80d48362ac24a5d3e
Hardware Model:      iPhone6,2
Process:             xxx [1971]
Path:                /var/mobile/Applications/33D1EAC9-8D24-4E40-805B-BD7C4FCD96FD/xxx.app/xxx
Identifier:          com.xx.xxx
Version:             1.0.0 (1.0.0)
Code Type:           ARM (Native)
Parent Process:      launchd [1]

Date/Time:           2013-10-30 19:50:38.812 +1000
OS Version:          iOS 7.0.3 (11B511)
Report Version:      104

Exception Type:  00000020
Exception Codes: 0x000000008badf00d
Highlighted Thread:  2

Application Specific Information:
xxx[1971] has active assertions beyond permitted time: 
{(
    <BKProcessAssertion: 0x17046ad40> identifier: Called by xxx, from unknown method process: xxx[1971] permittedBackgroundDuration: 180.000000 reason: finishTask owner pid:1971 preventSuspend  preventIdleSleep  preventSuspendOnSleep 
)}

Elapsed total CPU time (seconds): 0.440 (user 0.440, system 0.000), 4% CPU 
Elapsed application CPU time (seconds): 0.000, 0% CPU

尝试使用以下代码时会发生这种情况:

+(NSURLRequest*)updateLocation4SampleRequest_withUserId:(NSString*)userId userAPIToken:(NSString*)userAPIToken p1:(CLLocation*)p1 p2:(CLLocation*)p2 p3:(CLLocation*)p3 p4:(CLLocation*)p4 accuracy:(CLLocationAccuracy)accuracy
{
//    return [NSURLRequest requestWithURL: [[NSURL alloc] initWithString:[[NSString stringWithFormat: updateLocation4SampleRequestURL, OTNRequestURL, userId, userAPIToken, p1.coordinate.latitude, p1.coordinate.longitude, p2.coordinate.latitude, p2.coordinate.longitude, p3.coordinate.latitude, p3.coordinate.longitude, p4.coordinate.latitude, p4.coordinate.longitude, accuracy] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]];

    NSString *post = [NSString stringWithFormat: updateLocation4SampleRequestURL, userId, userAPIToken, p1.coordinate.latitude, p1.coordinate.longitude, p2.coordinate.latitude, p2.coordinate.longitude, p3.coordinate.latitude, p3.coordinate.longitude, p4.coordinate.latitude, p4.coordinate.longitude, accuracy];

    NSLog(@"%@",post);
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

    NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [[NSURL alloc] initWithString:OTNRequestURL] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:7];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
    [request setHTTPBody:postData];

    return request;
}

以及调用它并启动异步请求的函数。

// start the Link Maker search
        NSURLRequest* request = [OTNUtil updateLocation4SampleRequest_withUserId:userId     userAPIToken:user_api_token p1:p1 p2:p2 p3:p3 p4:p4     accuracy:OTNDataManager.app.currentLocation.horizontalAccuracy];
        NSLog(@"%@, (UPDATELOCATION) user id: %@",[request URL], userId);


        [NSURLConnection sendAsynchronousRequest:request queue:_requestOperationQueue completionHandler:^(NSURLResponse* response, NSData* data, NSError* error) {
            //The first checkin has occurred bool is used to skip the splash screen.
            self.firstCheckinHasOccurred = YES;

            // Save the downloaded data
            NSError* jsonError = nil;
            NSDictionary* resultDictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&jsonError];
            if(jsonError != nil) {
                // do something with the error here
                NSLog(@"JSON Error: %@", jsonError);
                //    callback(nil, jsonError);
                if (OTNDataManager.shared.settingsAutoCheckin) {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [OTNDataManager.app setLocationUpdateInterval:15.0 * 60.0];
                    });
                }

            } else if (resultDictionary != nil) {
              <SNIP....>
            }
          }];

确认一下……我只在运行 7.0.3 的 iPhone 5S 上看到了这一点,但没有看到两个单独的 iPhone 5,一个运行 7.0.3,另一个运行 6.1.4。它还在运行 7.0.2 的 iPhone 4S 上工作。此外,如果在绑定到 Xcode 的情况下运行代码,则不会发生这种情况,只有在发布模式下运行应用程序的编译版本时才会发生。

如果有人知道这里发生了什么,请告诉我。

4

2 回答 2

0

This issue is annoying which is hard to debug by breakpoint, I suggest you try some trick when app resign active as following, to apply for more time from system:

    __block UIBackgroundTaskIdentifier backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{


        [[UIApplication sharedApplication] endBackgroundTask:backgroundTaskIdentifier];
        backgroundTaskIdentifier = backgroundTaskIdentifier;
    }];
于 2014-12-29T03:32:12.843 回答
0

这些是看门狗超时崩溃报告,您可以通过臭名昭著的“吃了不好的食物”(0x8badf00d)异常代码来识别它们。有关如何破译崩溃日志和潜在解决方案的更多信息,请访问:

https://developer.apple.com/library/ios/qa/qa1693/_index.html

于 2015-04-23T15:01:56.043 回答