UILocalNotification自动删除

时间:2015-12-02 12:41:43

标签: ios uilocalnotification

我正在使用VOIP iOS应用程序,我必须在通话时显示本地通知,而应用程序处于后台模式我就像这样做

在appdelegate中注册通知

UIUserNotificationType types            = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *mySettings  = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];

显示通知

if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
    UILocalNotification* localNotif = [[UILocalNotification alloc] init];
    if (localNotif) {
        localNotif.soundName = UILocalNotificationDefaultSoundName;

        localNotif.alertTitle = @"Call From";
        localNotif.alertBody = [NSString stringWithFormat:@"%@", callerName];
        localNotif.alertAction = @"Receive";
        localNotif.applicationIconBadgeNumber = 1;

        localNotif.fireDate = [NSDate date];
        localNotif.userInfo = @{@"name":callerName};
        [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    }
}

本地通知显示为顶部警报,但当用户未参加通话或其他用户断开呼叫时,本地通知会自动从通知中心删除,这非常奇怪,我用Google搜索太多但没有成功提示某些解决方案。 提前谢谢。

0 个答案:

没有答案