<application>有超出允许时间的有效断言 - 仅适用于iPhone 5S,适用于iPhone 5,4s和4 </application>

时间:2013-10-31 00:15:24

标签: ios objective-c ios6 ios7 nsurlconnection

我收到以下崩溃报告,该应用在后台与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;
}

调用它并启动asyncrequest的函数。

// 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时运行代码,只有在发布模式下运行应用程序的编译版本时才会发生这种情况。

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

2 个答案:

答案 0 :(得分:0)

这个问题很烦人,很难通过断点调试,我建议你尝试一些技巧,当应用程序辞职活动如下,从系统申请更多时间:

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


        [[UIApplication sharedApplication] endBackgroundTask:backgroundTaskIdentifier];
        backgroundTaskIdentifier = backgroundTaskIdentifier;
    }];

答案 1 :(得分:0)

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

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