UILocalNotification custom sound

2019-02-17 01:10发布

I have been searching for a solution for hours.. with absolutely zero luck.

I set up a Local Notification:

UILocalNotification *notif = [[cls alloc] init];

[dateComp setDay:j+1];
[dateComp setHour:[[time objectAtIndex:0] integerValue]+offset];
[dateComp setMinute:[[time objectAtIndex:1] integerValue]];

NSLog(@"Year: %i, Month: %i, Day: %i, Time:%i:%i\n",[dateComp year], [dateComp month], 
                    [dateComp day], [dateComp hour], [dateComp minute]);

notif.fireDate = [gregorian dateFromComponents:dateComp];
notif.timeZone = [NSTimeZone defaultTimeZone];

notif.alertBody = [names objectAtIndex: k];
notif.soundName = @"fireburn.caf";

Notice the sound name...

I tried to put 10 sounds (aiff, wav, caf...etc), but the notification just pops up with the default sound :/

I have the "fireburn.caf" file in the Resources folder.

Why is it not playing my sound?????

Thanks.

3条回答
何必那么认真
2楼-- · 2019-02-17 02:01

are you cleaning the old notifications with

UIApplication* app = [UIApplication sharedApplication];
NSArray*  oldNotifications = [app scheduledLocalNotifications];

// Clear out the old notification before scheduling a new one.
[app cancelAllLocalNotifications];

?

查看更多
劳资没心,怎么记你
3楼-- · 2019-02-17 02:02

ANSWER:

Nothing wrong with the code..

It's just that the stupid iPhone didn't cancel the old notifications that I made with the default sound -_-;

When I cleaned the project, deleted the app from the phone AND REBOOTED the phone THEN it worked..

Hope someone finds this helpful.

查看更多
相关推荐>>
4楼-- · 2019-02-17 02:12

Try this:

notif.soundName = [strSoundFileName copy];
查看更多
登录 后发表回答