Вопрос

I am developing an iphone app in which i am using UILocalNotifications. When notification occurs, notification banner is displaying but there is no sound. i.e sound in disabled(off) from NotificationCenter. How can i enable(On) notification sound by default without going to settings. Thanks is advance

I am using

UILocalNotification *notification = [[UILocalNotification alloc]init];
[notification setAlertBody:alertBody];
[notification setFireDate:thedate2];
[notification setTimeZone:[NSTimeZone defaultTimeZone]];
notification.soundName = UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication]scheduleLocalNotification:notification];
Это было полезно?

Решение

It's absolutely not possible to override the global Notification Center settings programatically.

If it were, it would lead to chaos where apps ignore peoples preferences.

Imagine you're in an interview or meeting and some stupid app makes a ridiculous noise - even though you had your notifications on silent, how annoying would that be?

Другие советы

Try this one:

    UILocalNotification *localNotification1 = [[UILocalNotification alloc] init];
    localNotification1.fireDate = thedate2;
    localNotification1.alertBody = alertBody;
    localNotification1.repeatInterval = NSWeekCalendarUnit;
    localNotification1.soundName = @"sound.caf";
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification1];

Use a sound with .caf format. I think this will help you. :)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top