NSString *strMusic = @"../Documents/heartbeats.m4a"; //声音文件不要超过30秒
NSString *strImage = @"../Documents/imm.png";
//如果用下面注释的方式访问Documents的声音和图片,不能实现想要的效果,必须用上面的方式
//NSArray *arrPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//NSString *strDoc = [arrPath objectAtIndex:0];
//NSString *strImage = [strDoc stringByAppendingPathComponent:@"imm.png"];//NSString *strMusic = [strDoc stringByAppendingPathComponent:@"heartbeats.m4a"];
UILocalNotification *notification=[[UILocalNotification alloc] init];
notification.fireDate=[NSDate dateWithTimeIntervalSinceNow:10];
notification.timeZone=[NSTimeZone defaultTimeZone];
notification.repeatInterval = NSSecondCalendarUnit;
notification.alertAction = [NSString stringWithFormat:@" 显示闹钟"];
notification.alertBody= [NSString stringWithFormat:@"我的闹钟"];
notification.soundName = strMusic;
notification.alertLaunchImage = strImage;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
在模拟器和iphone4(5.1系统)测试通过,不知道低版本是否支持!还有不知道能否通过苹果审核?
本文介绍如何在iOS应用中正确设置本地通知的声音和图片资源,并提供了一个具体的代码示例。需要注意的是,声音文件不宜过长,且推荐使用特定路径而非相对路径来引用资源。
2200

被折叠的 条评论
为什么被折叠?



