简体   繁体   中英

Local notification sound should be on by default

I am developing an iphone app in which i am using UILocalNotifications . When notification occurs, notification banner is displaying but there is no sound. ie 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. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM