iOS:以编程方式启用/禁用推送通知的声音

时间:2017-04-20 15:27:33

标签: ios objective-c iphone swift push-notification

我想在我的应用中添加一项功能,即用户可以启用和禁用推送通知声音。这是UI:

enter image description here

我正在使用以下代码启用和禁用声音:

 [[UIApplication sharedApplication] unregisterForRemoteNotifications];
        UIUserNotificationType allNotificationTypes;
        UIUserNotificationSettings *settings;
        //
        if(sound==0 || sound==1)
        {
        allNotificationTypes =
            (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
        settings = [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
        }
        else if(sound==2)
        {
            allNotificationTypes =
            (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
            settings = [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
        }

        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
        [FIRApp configure];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenRefreshNotification:)
                                                     name:kFIRInstanceIDTokenRefreshNotification object:nil];

我正在使用firebase进行推送通知。

0 个答案:

没有答案