您的位置:首页 > 产品设计 > UI/UE

UILocalNotification 使用Documents目录的声音文件和图片文件

2012-05-03 19:13 239 查看
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系统)测试通过,不知道低版本是否支持!还有不知道能否通过苹果审核?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: