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”是我的应用套装ID。 当应用程序在10分钟后进入后台时,应用程序被杀死。我有双“endBackgroundTask”。我没有创建任何NSURLConnections。但应用程序被杀了。 (我在ipod4上运行,10分钟后应用程序被杀死。我在Xcode中找到上面的日志 - &gt; Organizer-Myipod-&gt;控制台)
即使应用程序进入后台超过10分钟,我也想开发一种可以接收CMAccelerationData的软件。
我该怎么办?谁能帮我?谢谢......
我的项目网址:http://qq644531343.opendrive.com/files/Ml8yMjE4MjIzN19heHNtQl82YzYz/Testautoreleasepool2.zip
主要代码:
- (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];
}
});
}