Presenting a local notification immediately while running in the background

来源:互联网 发布:python keras实例 编辑:程序博客网 时间:2024/06/05 08:05
- (void)applicationDidEnterBackground:(UIApplication *)application {      NSLog(@"Application entered background state.");      // bgTask is a property of the class      NSAssert(self.bgTask == UIInvalidBackgroundTask, nil);      bgTask = [application beginBackgroundTaskWithExpirationHandler: ^{          dispatch_async(dispatch_get_main_queue(), ^{              [application endBackgroundTask:self.bgTask];              self.bgTask = UIInvalidBackgroundTask;          });}];      dispatch_async(dispatch_get_main_queue(), ^{          while ([application backgroundTimeRemaining] > 1.0) {init];friend];nil);NSString *friend = [self checkForIncomingChat];if (friend) {    UILocalNotification *localNotif = [[UILocalNotification alloc]    if (localNotif) {        localNotif.alertBody = [NSString stringWithFormat:            NSLocalizedString(@"%@ has a message for you.", nil),        localNotif.alertAction = NSLocalizedString(@"Read Message",        localNotif.soundName = @"alarmsound.caf";        localNotif.applicationIconBadgeNumber = 1;                      [application presentLocalNotificationNow:localNotif];                      [localNotif release];                      friend = nil;                      break;} }          }          [application endBackgroundTask:self.bgTask];          self.bgTask = UIInvalidBackgroundTask;});}

0 0
原创粉丝点击