Why are my local notifications not having sound on by default in iOS 7?

大兔子大兔子 提交于 2019-12-07 03:22:45

问题


My app uses geofencing and sends a notification.

By default, sounds are off in Settings - Notifications for the app.

iOS 7 to be precise.

Does anyone know how to fix this?

Here is the code responsible for this:

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
        localNotif.fireDate = [NSDate dateWithTimeInterval:5 sinceDate:[NSDate date]];
        localNotif.timeZone = [NSTimeZone defaultTimeZone];
        localNotif.alertBody = [NSString stringWithFormat:@"You are near %@. Don't forget to check in!",place.name];
        localNotif.soundName = UILocalNotificationDefaultSoundName;
        localNotif.applicationIconBadgeNumber = 0;
        [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

回答1:


If the sound is turned off for your app in the Settings app, then your notification will not play any sound. The user does not allow you to do that.

If the sound is not turned off in the Settings app, that code that you posted should work.

Also if the user set the ringer switch off, then there will be no sound played.




回答2:


Have you set the applicationIconBadgeNumber in

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions?

Comment this code, and try again.....I don't why, but I got the same problem. After I commented this line, my app works correctly.



来源:https://stackoverflow.com/questions/19303796/why-are-my-local-notifications-not-having-sound-on-by-default-in-ios-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!