registerUserNotificationSettings不显示警报

时间:2015-05-18 19:12:14

标签: ios objective-c alert uilocalnotification

我要求用户允许在iOS 8上使用本地通知,如下所示:

    if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
    UIUserNotificationType types = UIUserNotificationTypeBadge |
    UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
    UIUserNotificationSettings *notificationSettings =
    [UIUserNotificationSettings settingsForTypes:types categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
}

我在AppDelegate中这样处理:

-(void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
[[NSNotificationCenter defaultCenter] postNotificationName:@"didRegisterUserNotificationSettings" object:nil];
}

但是没有显示警报?它会直接跳到委托回调。为什么是这样?我在iOS模拟器中这样做。

谢谢!

1 个答案:

答案 0 :(得分:1)

仅显示一次警报,要在模拟器上再次显示,请按iOS Simulator - > Reset Contents and Settings