Local notification in iOS coming without any sound

2019-07-19 07:41发布

问题:

-(void)notifyMe
{
    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:0.1];
    localNotification.timeZone = [NSTimeZone defaultTimeZone];
    localNotification.alertBody = @"Alert";
    localNotification.alertAction = @"Local notification";
    localNotification.soundName = UILocalNotificationDefaultSoundName;
    localNotification.alertLaunchImage = nil;
    localNotification.userInfo = nil;
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}

This is the method I am calling for local notification. This is working fine with other applications. But with my working one, notification is coming but with no sound.

I guess there is some problem with app setting, but I am unable to find it out.

回答1:

I found your question as I had run into the same problem. Turns out it was a simple fix on my part, my code was fine all I had to do was enable push notifications for my app (which I had already done but was getting no sound or badge), and then switch Badge App Icon and Sound to ON.

I'm surprised there have been no other answers to this question in 6 months.