gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 21:02:02 24 4
gpt4 key购买 nike

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

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com