iOS Can i play sound using local notification when app is in foreground [closed]

醉酒当歌 提交于 2019-12-11 03:43:51

问题


Local Notification sound is not playing when app is in foreground : I Used following code

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];

回答1:


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];


来源:https://stackoverflow.com/questions/16030305/ios-can-i-play-sound-using-local-notification-when-app-is-in-foreground

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!