如何使用通知请求禁用视图?

时间:2015-07-02 08:47:26

标签: ios iphone notifications

如何激活和禁用本地通知?

第一次打开应用时,会出现带有通知请求的此视图。如何在应用程序启动时消除此alertView以获取通知?我想在设置中使用开关。

那么,这是一种从appDelegate转换代码的方法,来自settingsView的转换?

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}

或者我可以设置从开始到通知?在我使用switch创建或不通知之后。

1 个答案:

答案 0 :(得分:1)

在settingsView.m文件中尝试此操作

       - (IBAction)switchValueChanged:(id)sender
     {
if (self.switchNotificationSetting.isOn)
{
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
    {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    else
    {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
         (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
    }
}
 }

第二次以后它不会显示警告,用户允许通知或禁止,警报只出现一次。 你需要添加iboutlet和uiswitch的动作