私はvoipアプリケーションを持っています。
私はUILocalNotification
自分のアプリケーションで使用して、アプリケーションがバックグラウンドにあるときに着信コールの通知を警告しています。
アプリケーションがバックグラウンドの場合、着信を取得した後、次の関数が呼び出されます。
-(void)showLocalNotification:(NSNotification *)notification {
NSDictionary *dic = notification.userInfo;
NSString *msg = [dic objectForKey:@"msg"];
NSString *sound = [dic objectForKey:@"sound"];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
UILocalNotification *_localNotification = [[UILocalNotification alloc]init];
//setting the fire dat of the local notification
_localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
//setting the time zone
_localNotification.timeZone = [NSTimeZone defaultTimeZone];
//setting the message to display
_localNotification.alertBody = msg;
//default notification sound
if ([sound length]==0) {
_localNotification.soundName = UILocalNotificationDefaultSoundName;
} else {
_localNotification.alertAction = NSLocalizedString(@"Receive", nil);
_localNotification.soundName = @"myringtone.aif";
}
//displaying the badge number
_localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication]applicationIconBadgeNumber]+1;
//schedule a notification at its specified time with the help of the app delegate
[[UIApplication sharedApplication]scheduleLocalNotification:_localNotification];
}
Cancel
この関数は、2 つのボタンでReceive
1 秒後に起動するアラートを表示するように scheduleLocal 通知を設定します。
問題は次のとおりです。
このローカル通知は、バックグラウンド タスクが次のように開始された場合にのみユーザーに表示されます。
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
}
しかし、10 分後にバックグラウンド タスクが停止します。その後、ローカル通知は起動してもユーザーに表示されません (起動後にログが出力されます)。
applicationDidEnterBackground
長時間実行するバックグラウンド タスクを再起動するために、関数を次のように変更しました。しかし、できません。
- (void)applicationDidEnterBackground:(UIApplication *)application
{
expirationHandler = ^{
[app endBackgroundTask:self.bgTask];
self.bgTask = UIBackgroundTaskInvalid;
self.bgTask = [app beginBackgroundTaskWithExpirationHandler:expirationHandler];
}
self.bgTask = [app beginBackgroundTaskWithExpirationHandler:expirationHandler];
}
質問は次のとおりです。
アプリケーションがバックグラウンドにあるときに、ローカル通知を起動してユーザーに表示する方法はありますか?
バックグラウンド タスクが必須の場合、10 分後にローカル通知を表示してユーザーを表示するのに時間がかかるのはなぜですか?
iPhone 3gs
、iPhone 4
およびを使用してiPhone 5
います。