本地通知?

我的应用程序主要是一个真正没有连接到互联网的服务器的客户端。 它连接到Polycom编解码器并pipe理2个端点之间的video呼叫。 所以我的应用程序可以发送像结束呼叫,音量等命令…但是我的问题是这样的。 当有来电时,我需要某种通知,并且应用程序不在前台。 由于服务器没有互联网接入APNS /推送通知不会为我工作。 我已经研究过这样的事情。 这似乎保持我的客户端运行,但我不能做一个警报,因为我的应用程序是在后台。

所以除了如何解决我的问题的基本知识我的问题是:

我可以使用链接中列出的技术将我的应用程序带到前台(像下面这样做)。 我可以从日志中看到这个代码保持我的代码运行。 我知道我的while循环是不正确的,最后我会需要KVO,但不pipe这个答案是否应该。 (有一件事我不明白这是保持我的整个应用程序运行,而不是我在那里的类bcClient?)

- (void)applicationDidEnterBackground:(UIApplication *)application { [bcClient connect]; bgTask = [app beginBackgroundTaskWithExpirationHandler:expirationHandler]; // Start the long-running task and return immediately. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ while(1) { sleep(3); NSLog(@"held join %d",bcClient.heldjoin); if (bcClient.heldjoin == 602 || bcClient.heldjoin == 604 || bcClient.heldjoin == 513) { NSLog(@"incoming call"); } } }); } 

如果我不能把我的应用程序放在前台,那么是否有本地推送通知(不需要APNS服务器)?

我有一种感觉,这是不可能的,但我想我会问。

这是我的答案。 这使我的客户端应用程序在后台运行,并在来电时显示通知。

AppDelegate.h

 @interface CameleonAppDelegate : NSObject <UIApplicationDelegate> { CrestronClient *cClient; CrestronControllerValues *CCV; RootViewController *rootViewController; CrestronValues *crestronValues; UIBackgroundTaskIdentifier bgTask; dispatch_block_t expirationHandler; UIApplication* app; BOOL showedCall; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext; @property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel; @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator; - (void)saveContext; - (NSURL *)applicationDocumentsDirectory; -(void)save; -(void)load; - (void)backgroundHandler; @end 

AppDelegate.m(只是didFinishLaunchingWithOptionsapplicationDidEnterBackground

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { app = [UIApplication sharedApplication]; expirationHandler = ^{ [app endBackgroundTask:bgTask]; bgTask = UIBackgroundTaskInvalid; bgTask = [app beginBackgroundTaskWithExpirationHandler:expirationHandler]; }; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSArray *keys = [NSArray arrayWithObjects:@"IPaddress", @"PortNumber",@"IPID", nil]; NSArray *objs = [NSArray arrayWithObjects:@"10.8.40.64", @"41794",@"3", nil]; //10.8.30.143 10.8.40.64 NSDictionary *dict = [NSDictionary dictionaryWithObjects:objs forKeys:keys]; [defaults registerDefaults:dict]; CCV = [CrestronControllerValues sharedManager]; [CCV setIpAddress:[defaults stringForKey:@"IPaddress"]]; [CCV setPortNumber:[defaults stringForKey:@"PortNumber"]]; [CCV setIPID:[defaults stringForKey:@"IPID"]]; cClient = [CrestronClient sharedManager]; rootViewController = [[RootViewController alloc]initWithNibName:@"RootViewController" bundle:nil]; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; return YES; } - (void)applicationDidEnterBackground:(UIApplication *)application { showedCall = FALSE; BOOL backgroundAccepted = [[UIApplication sharedApplication] setKeepAliveTimeout:600 handler:^{ [self backgroundHandler]; }]; if (backgroundAccepted) { NSLog(@"VOIP backgrounding accepted"); } bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ [app endBackgroundTask:bgTask]; bgTask = UIBackgroundTaskInvalid; }]; // Start the long-running task dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ while (1) { sleep(4); //NSLog(@"BGTime left: %f", [UIApplication sharedApplication].backgroundTimeRemaining); if ([rootViewController isIncomingCall] && showedCall != TRUE) { UILocalNotification *localNotif = [[UILocalNotification alloc] init]; if (localNotif) { localNotif.alertBody = [NSString stringWithFormat:@"Incoming Call."]; localNotif.alertAction = NSLocalizedString(@"Accept Call", nil); localNotif.soundName = @"alarmsound.caf"; localNotif.applicationIconBadgeNumber = 1; [application presentLocalNotificationNow:localNotif]; [localNotif release]; } showedCall = TRUE; } } }); } - (void)backgroundHandler { NSLog(@"### -->VOIP backgrounding callback"); bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ [app endBackgroundTask:bgTask]; bgTask = UIBackgroundTaskInvalid; }]; // Start the long-running task dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ while (1) { NSLog(@"BGTime left: %f", [UIApplication sharedApplication].backgroundTimeRemaining); [rootViewController isIncomingCall]; sleep(1); } }); }