ozd
ozd

Reputation: 1284

Remove sound from notification

I'm trying to create a UISwitch so user can choose not to get push sounds from inside the app. Is it possible? i've tried to register again without sound -

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

and all is does is disable the users ability to toggle between sound on/off in the iphone settings, but still remembers what the user chosen when the ability to toggle was available.

for example - if the user enables the push sound from the iphone settings and than disable it from the app - he now cant see or use ,the notification sound toggle switch, on the iphone settings but still get sound when receiving push.

thanks

Upvotes: 2

Views: 3243

Answers (1)

6rod9
6rod9

Reputation: 1457

It's not possible from the client side (iOS app). But, you can remove the sound key in the payload you send from your server side (backend) and the push notification will be silent.

With default sound:

{"aps":{"alert":"Hello","badge":1,"sound":"default","category":"your_category_key"}}

With NO sound:

{"aps":{"alert":"Hello","badge":1,"category":"your_category_key"}}

Upvotes: 7

Related Questions