iOS当app位于前台时,我可以使用本地通知播放声音 [英] iOS Can i play sound using local notification when app is in foreground
本文介绍了iOS当app位于前台时,我可以使用本地通知播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
本地通知声音未播放:我使用以下代码
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];
推荐答案
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];
这篇关于iOS当app位于前台时,我可以使用本地通知播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文