iphone - iOS 当应用程序位于前台时,我可以使用本地通知播放声音吗

标签 iphone ios5 ios6

当应用程序位于前台时,本地通知声音不播放:我使用了以下代码

UILocalNotification *notif = [[cls alloc] init];
notif.fireDate = [datePicker date];         
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.alertBody = @"Did you forget something?";
notif.alertAction = @"Show me";
notif.soundName = @"step.mp3";//UILocalNotificationDefaultSoundName;
notif.applicationIconBadgeNumber = 1;

NSDictionary *userDict = [NSDictionary dictionaryWithObject:reminderText.text
                                                                 forKey:kRemindMeNotificationDataKey];
notif.userInfo = userDict;

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

最佳答案

UILocalNotification *localNotification = [[UILocalNotification alloc]init];

   // Set the notification time.
    localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];

   // You can specify the alarm sound here.
   localNotification.soundName = UILocalNotificationDefaultSoundName;
   //OR
   localNotification.soundName = @"sound.caf";

   // Set the alertbody of the notification here.
    localNotification.alertBody = @"Test Alert";

   // Create the buttons on the notification alertview.
    localNotification.alertAction = @"View";

   // You can also specify custom dictionary to store informations
    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"alarm#2" forKey:@"notifiKey"];
    localNotification.userInfo = infoDict;

    //Repeat the notification.
    localNotification.repeatInterval = NSDayCalendarUnit;

// Schedule the notification
[[UIApplication sharedApplication]scheduleLocalNotification:localNotification];

关于iphone - iOS 当应用程序位于前台时,我可以使用本地通知播放声音吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16030305/

相关文章:

iphone - 在 iPhone 中将 .mm 文件转换为 .m 文件

ios - iPad 版主详细信息应用程序

ios - 不使用 Storyboard 的应用程序状态保存和恢复?

ios - 更改 spritekit 中的初始场景

iphone - 如何知道捏合手势何时完成(UIGestureRecognizer)

objective-c - 应用未运行时推送通知 - launchOptions 字典为空

ios - iOS5 中我的 UITableView 出现 dequeueReusableCellWithIdentifier 错误

ios 添加按钮自动布局

ios - 从另一个应用程序打开设置应用程序

iphone - 如何在 subview 中访问ViewController的数据?