Jul 3 18:20:22 Testautoreleasepool[9079] <Warning>: update2: x:-1.004532 y:0.006363 z:0.093887 1311
Jul 3 18:20:22 Testautoreleasepool[9079] <Warning>: update2: x:-1.004532 y:0.006363 z:0.093887 1312
Jul 3 18:20:22 Testautoreleasepool[9079] <Warning>: update2: x:-1.004532 y:0.006363 z:0.093887 1313
Jul 3 18:20:22 Testautoreleasepool[9079] <Warning>: update2: x:-1.004532 y:0.006363 z:0.093887 1314
Jul 3 18:20:22 Testautoreleasepool[9079] <Warning>: update2: x:-1.004532 y:0.006363 z:0.093887 1315
Jul 3 18:20:22 backboardd[66] <Warning>: Testautorelease[9079] has active assertions beyond permitted time:
{(
<BKProcessAssertion: 0x1dd68310> identifier: UIKitBackgroundCompletionTask process: Testautorelease[9079] permittedBackgroundDuration: 600.000000 reason: finishTask owner pid:9079 preventSuspend preventIdleSleep
)}
Jul 3 18:20:22 backboardd[66] <Warning>: Forcing crash report of Testautorelease[9079]...
Jul 3 18:20:22 ReportCrash[9134] <Notice>: MS:Notice: Installing: (null) [ReportCrash] (793.00)
Jul 3 18:20:23 backboardd[66] <Warning>: Finished crash reporting.
Jul 3 18:20:23 com.apple.launchd[1] <Notice>: (UIKitApplication:net.imore.testAcc[0xeeb9]) Exited: Killed: 9
Jul 3 18:20:23 ReportCrash[9134] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
Jul 3 18:20:23 backboardd[66] <Warning>: Application 'UIKitApplication:net.imore.testAcc[0xeeb9]' exited abnormally with signal 9: Killed: 9
"net.imore.testAcc" is my app bundle ID. When the App enter to the background after 10 minutes, the App was killed. I have double "endBackgroundTask". I didn't create any NSURLConnections. But the App was killed. (I run this on ipod4,and after 10 minutes the app is killed. I find the log above in Xcode->Organizer-Myipod->Console)
I want to develope a soft that can recieve CMAccelerationData even if the app enter to the background more than 10 minutes.
What can I do? Can anyone help me? thank you...
My project url: http://qq644531343.opendrive.com/files/Ml8yMjE4MjIzN19heHNtQl82YzYz/Testautoreleasepool2.zip
main code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//[self redirectNSLogToDocumentFolder];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(100, 200, 80, 40);
[btn addTarget:self action:@selector(changebg) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:btn];
//init motionManager
motionManager = [[CMMotionManager alloc] init];
motionManager.accelerometerUpdateInterval = 1.0f;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
-(void)changebg
{
int i = arc4random()%255+1;
int j = arc4random()%255+1;
int k = arc4random()%255+1;
[self.window setBackgroundColor:[UIColor colorWithRed:i/255.0f green:j/255.0f blue:k/255.0f alpha:1.0f]];
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
@autoreleasepool {
NSLog(@"enter background");
[self update];
}
self.backgroundTaskIdentifier =
[application beginBackgroundTaskWithExpirationHandler:^(void) {
NSLog(@"begin in background after 10 minutes");
[motionManager stopAccelerometerUpdates];
motionManager.accelerometerUpdateInterval = 1.0f;
[self update2];
[self endBackgroundTask];
}];
}
-(void)update
{
NSLog(@"update");
[motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue]
withHandler:^(CMAccelerometerData *accelerometerData,NSError *error)
{
CMAcceleration acceleration=accelerometerData.acceleration;
NSLog(@"update: x:%f y:%f z:%f timeremian:%f",acceleration.x,acceleration.y,acceleration.z,[UIApplication sharedApplication].backgroundTimeRemaining);
}];
}
-(void)update2
{
int i=0;
NSLog(@"begin back acc");
while (1) {
@autoreleasepool {
//app enter foreground
if ([[UIApplication sharedApplication] backgroundTimeRemaining] > 600.0f) {
break;
}
CMAcceleration acceleration = motionManager.accelerometerData.acceleration;
NSLog(@"update2: x:%f y:%f z:%f %d",acceleration.x,acceleration.y,acceleration.z,i++);
}
}
NSLog(@"%s stoped acc",__func__);
[motionManager stopAccelerometerUpdates];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
NSLog(@"enter foreground");
if (self.backgroundTaskIdentifier != UIBackgroundTaskInvalid){
[self endBackgroundTask];
}
}
- (BOOL) isMultitaskingSupported{
BOOL result = NO;
if ([[UIDevice currentDevice]
respondsToSelector:@selector(isMultitaskingSupported)]){
result = [[UIDevice currentDevice] isMultitaskingSupported];
}
return result;
}
- (void) endBackgroundTask{
NSLog(@"end task");
dispatch_queue_t mainQueue = dispatch_get_main_queue();
AppDelegate
*weakSelf = self;
dispatch_async(mainQueue, ^(void) {
AppDelegate
*strongSelf = weakSelf;
if (strongSelf != nil){
[[UIApplication sharedApplication]
endBackgroundTask:self.backgroundTaskIdentifier];
strongSelf.backgroundTaskIdentifier = UIBackgroundTaskInvalid;
[motionManager stopAccelerometerUpdates];
}
});
}