M.A*_*ash 10 iphone objective-c ipad ios socket.io
我使用SocketRocket创建了一个聊天应用程序,当我退出应用程序(进入后台模式)时,我想收到聊天消息!所以我可以通过称之为VoIP应用程序来做到这一点,但有些人说苹果将拒绝它从App Store,除非它也真的做VoIP.那么我怎么能这样做呢?如果这样做的唯一方法是将它称为VoIP应用程序whatsapp如何处理这种情况?
以下是我在后台保持应用程序活动的方法:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSLog(@"Application entered background state.");
NSAssert(self.backgroundTask == UIBackgroundTaskInvalid, nil);
self.didShowDisconnectionWarning = NO;
self.backgroundTask = [application beginBackgroundTaskWithExpirationHandler: ^{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Background task expired");
if (self.backgroundTimer)
{
[self.backgroundTimer invalidate];
self.backgroundTimer = nil;
}
[application endBackgroundTask:self.backgroundTask];
self.backgroundTask = UIBackgroundTaskInvalid;
});
}];
dispatch_async(dispatch_get_main_queue(), ^{
self.backgroundTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(timerUpdate:) userInfo:nil repeats:YES];
});
}
- (void) timerUpdate:(NSTimer*)timer {
UIApplication *application = [UIApplication sharedApplication];
NSLog(@"Timer update, background time left: %f", application.backgroundTimeRemaining);
if ([application backgroundTimeRemaining] < 60 && !self.didShowDisconnectionWarning)
{
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif) {
localNotif.alertBody = @"Background session will expire in one minute.";
localNotif.alertAction = @"OK";
localNotif.soundName = UILocalNotificationDefaultSoundName;
[application presentLocalNotificationNow:localNotif];
}
self.didShowDisconnectionWarning = YES;
}
if ([application backgroundTimeRemaining] < 10)
{
// Clean up here
[self.backgroundTimer invalidate];
self.backgroundTimer = nil;
[application endBackgroundTask:self.backgroundTask];
self.backgroundTask = UIBackgroundTaskInvalid;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7903 次 |
| 最近记录: |