Noor
Noor

Reputation: 20150

iOS Notification not playing sound

I've created a notification in my iOS app using iOS 8. The notification is correctly being displayed but it's not playing the sound, although UIUserNotificationTypeSound was registered and default sound name was specified. How can I make the sound play when I get the notification?

Registering UIUserNotificationTypeSound

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]]

        return YES;
    }

Setting default sound name

localNotif.soundName = UILocalNotificationDefaultSoundName;

Upvotes: 0

Views: 377

Answers (1)

Janmenjaya
Janmenjaya

Reputation: 4163

I have not tested your code But comparing to my code, I found you are not calling [application registerForRemoteNotifications]; method

if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
    // iOS 8 Notifications
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

    [application registerForRemoteNotifications];
}

Try this, I guess it will help you.

Upvotes: 1

Related Questions