闹钟 iphone sdk 问题

发布于 2025-01-05 12:02:46 字数 1116 浏览 0 评论 0原文

这是一些代码。

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

    if ([oldNotifications count] > 0) [app cancelAllLocalNotifications];


    NSString *filePath = [DOCUMENTS stringByAppendingPathComponent:@"personal2.wav"];
    //NSLog(@"%@",filePath);
    //filePath = [[NSBundle mainBundle] pathForResource:@"wolf" ofType:@"wav"];
    UILocalNotification *localNotif = [[UILocalNotification alloc]init];
    localNotif.fireDate = alarmPicker.date ;
    localNotif.timeZone = [NSTimeZone localTimeZone];
    localNotif.alertBody = @"Alarm";
    localNotif.alertAction = @"View";
    localNotif.soundName = filePath;
    localNotif.applicationIconBadgeNumber = 1;
    //localNotif.repeatInterval = NSYearCalendarUnit;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    [localNotif release];

所以它只显示警报但不播放 wav。当我单击“查看”时,它会启动应用程序,并在 didReceiveLocalNotification 方法中再次播放这首歌,听起来不错。 有人可以帮我解决问题吗?谢谢

​我读到 wav 的持续时间应该少于 30 秒,而它是 22 秒,所以它应该播放 PS2 是否有一种在本地通知启动时重复播放歌曲的方式。谢谢

Here is some code.

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

    if ([oldNotifications count] > 0) [app cancelAllLocalNotifications];


    NSString *filePath = [DOCUMENTS stringByAppendingPathComponent:@"personal2.wav"];
    //NSLog(@"%@",filePath);
    //filePath = [[NSBundle mainBundle] pathForResource:@"wolf" ofType:@"wav"];
    UILocalNotification *localNotif = [[UILocalNotification alloc]init];
    localNotif.fireDate = alarmPicker.date ;
    localNotif.timeZone = [NSTimeZone localTimeZone];
    localNotif.alertBody = @"Alarm";
    localNotif.alertAction = @"View";
    localNotif.soundName = filePath;
    localNotif.applicationIconBadgeNumber = 1;
    //localNotif.repeatInterval = NSYearCalendarUnit;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    [localNotif release];

So it shows just alert but it is not playing wav. When i click View it starts the app and in didReceiveLocalNotification method i play this song again and it sounds good.
Can somebody help me with issue. Thanks

P.S. I read that duration of wav should be les than 30 sec and it is 22 seconds so it should play
P.S.2 Is it a way to repeat of playing the song when the localnotifications fires up. THANKS

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒芜了季节 2025-01-12 12:02:46

检查您的应用目标属性中是否已在必需的后台模式应用播放音频

Check if you have App plays audio in Required background modes in your app's target properties.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文