iOS¿ª·¢ - °Ù¶ÈµØͼºǫ́³ÖÐø¶¨Î»
ÖÇ°ÓÐ×öÒ»¸ö¶¨Î»µÄÏîÄ¿£¬ÀàËÆàÖàÖ´ò³µÄÇÑù¡£ ÐèÒªºǫ́³ÖÐø¶¨Î»¡£
ÕâÀïÑ¡ÔñÁ˰ٶȵØͼ£¬²»¹ýÔÚºǫ́³ÖÐø¶¨Î»·½Ã棬 ÖÇ°Ö»ÊǼòµ¥µÄÉèÖÃÈçÏÂ:
²»¹ý¾²âÊÔ·¢ÏÖ, ÕâÑùÉèÖÃÍ꣬ÔÚºǫ́ÔËÐдó¸Å30·ÖÖÓ£¬Óֻᱻcrashµô¡£ ÖØдò¿ªÓ¦ÓÃÔò×Ô¶¯»Ö¸´¶¨Î»¡£<†·Ÿ"http://www.bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD48cD48YnIgLz48L3A+PHA+tbHIu6Os1eKyu8rHztLDx8/r0qq1xNCnufujrMv50tTV28zawcvPwqOsyrXP1sHLuvPMqLPW0Pi2qM67oaM8L3A+PHA+19y1xMC0y7WjrL7NysfA+9PDvfjI67rzzKi6887Sw8e/ybLZv9i1xDEwt9bW06OswLTN6rPJ0rvQqcrCx+mhozwvcD48cD7OqrTvtb2z1tD4tqjOu6Osw78xMLfW1tOho9fUtq/W2NDCv6rG9Laozruho9Xi0fm+zb3ivvbOysziwcuhozwvcD48cD48YnIgLz48L3A+PHA+vt/M5cjnz8I6PC9wPjxwPjxiciAvPjwvcD48cD5BcHBEZWxlZ2F0ZS5oPGJyIC8+PC9wPjxwPjxwcmUgY2xhc3M9"brush:java;">@property (nonatomic, unsafe_unretained) UIBackgroundTaskIdentifier bgTask;
AppDelegate.m
- (void)backgroundHandler{ NSLog(@"### -->backgroundinghandler"); UIApplication* app = [UIApplication sharedApplication]; bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ [app endBackgroundTask:bgTask]; bgTask = UIBackgroundTaskInvalid; }]; // Start the long-running task dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // ÄúÏë×öµÄÊÂÇé, // ±ÈÈçÎÒÕâÀïÊÇ·¢Ë͹㲥, ÖØм¤»î¶¨Î» // È¡µÃiosϵͳΨһµÄÈ«¾ÖµÄ¹ã²¥Õ¾ ֪ͨÖÐÐÄ NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; //ÉèÖù㲥ÄÚÈÝ NSDictionary *dict = [[NSDictionary alloc]init]; //½«ÄÚÈÝ·â×°µ½¹ã²¥ÖÐ ¸øiosϵͳ·¢Ë͹㲥 // LocationThemeƵµÀ [nc postNotificationName:@"LocationTheme" object:self userInfo:dict]; }); }
- (void)applicationDidEnterBackground:(UIApplication *)application{ // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. BOOL backgroundAccepted = [[UIApplication sharedApplication] setKeepAliveTimeout:600 handler:^{ [self backgroundHandler]; }]; if (backgroundAccepted) { NSLog(@"backgrounding accepted"); } [self backgroundHandler];}
È»ºóÔÚ¿ªÆô¶¨Î»µÄλÖ㬳ÉΪ¹ã²¥½ÓÊÕÕߣ¬²¢ÇÒÖØм¤»î¶¨Î»
//³õʼ»¯BMKLocationService myLocService = [[BMKLocationService alloc]init]; myLocService.delegate = self; //Æô¶¯LocationService [myLocService startUserLocationService];
NSNotificationCenter *nc2 = [NSNotificationCenter defaultCenter]; // ³ÉΪÌýÖÚÒ»µÓй㲥¾ÍÀ´µ÷ÓÃself recvBcast:º¯Êý [nc2 addObserver:self selector:@selector(activeLocation:) name:@"LocationTheme" object:nil];
- (void) activeLocation:(NSNotification *)notify{ [myLocService stopUserLocationService]; //³õʼ»¯BMKLocationService myLocService = [[BMKLocationService alloc]init]; myLocService.delegate = self; //Æô¶¯LocationService [myLocService startUserLocationService];}
µ±È»£¬ÉÏÃæµÄ·½Ê½£¬¿ÉÄÜ·½·¨±È½ÏÔü£¬´úÂëҲдµÄ±È½ÏÂÒ¡£
Ö»ÊÇÌá¹Ò»ÖÖ½â¾ö°ì·¨¶øÒÑ¡£