我已经为我的应用程序完成了基本通知.我想在我的通知中添加声音效果.
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
if (localNotification == nil)
return;
localNotification.fireDate = [NSDate date];
//localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertBody = msg;
localNotification.soundName = @"Morse.aiff";
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
Run Code Online (Sandbox Code Playgroud)
如何添加音效?
我正在制作一个iPhone应用程序,我已经实现了本地通知的概念,提醒用户服用药物.
但在iOS中,我们一次不能安排超过64个通知.但是我在数据库中有许多日期时间条目.我如何安排超过64个通知?
我在App Store中有一个iPad应用程序,其逻辑很大程度上依赖于本地通知.换句话说,应用程序内发生的很多事情都是由委托方法应用程序didReceiveLocalNotification触发的.
随着今天发布的iOS 5,我发现可以通过"设置""在通知中心"或"不在通知中心"放置应用程序.到目前为止,我还没有在新文档中找到任何内容,但是我希望有一种方法可以将我的应用程序默认设置为"In Notification Center"(甚至可能将Sounds设置为活动状态,通知类型设置为Alert)除了向新用户明确说明他们下载并安装我的应用程序后,他们必须手动选择该应用程序为"在通知中心".
任何人都知道这是否可行?似乎由于应用程序可以注册本地通知,因此默认情况下它应该能够接收它(无论它是否在新的通知中心中显示警报或项目).提前致谢.
目前我有一个带闹钟的计时器(本地通知).
我想从这段代码创建一个计时器类来创建多个计时器和通知(最多5个),我正在努力学习如何使用类方法创建和取消唯一通知.
- (UILocalNotification *) startAlarm {
[self cancelAlarm]; //clear any previous alarms
alarm = [[UILocalNotification alloc] init];
alarm.alertBody = @"alert msg"
alarm.fireDate = [NSDate dateWithTimeInterval: alarmDuration sinceDate: startTime];
alarm.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:alarm];
}
Run Code Online (Sandbox Code Playgroud)
我的假设是,如果我有一个创建名为"alarm"的UILocalNotification的类方法,iOS会将所有通知视为相同的通知,并且以下方法将无法按照我希望的方式运行:
- (void)cancelAlarm {
if (alarm) {
[[UIApplication sharedApplication] cancelLocalNotification:alarm];
}
}
Run Code Online (Sandbox Code Playgroud)
所以我需要一种方法来命名这些UILocalNotifications,因为它们被创建,例如alarm1 alarm2 ... alarm5所以我可以取消正确的.
提前致谢.
如何将默认iOS声音(三音,钟声,玻璃,号角,贝尔,电子...)设置为本地通知声音?
我创建了本地通知,一切正常,但默认声音(三音).我想使用Chime或其他
我只知道如何使用我自己的声音文件:
localNotif.soundName = @"sound.wav";
Run Code Online (Sandbox Code Playgroud) 我正在创建一个包含Today Extension的应用程序.今天的扩展显示计时器列表,如果用户选择其中一个计时器,我想为该计时器创建和安排本地通知.
我的问题是通过这行代码完成通知的安排:
UIApplication.sharedApplication().scheduleLocalNotification(notification)
Run Code Online (Sandbox Code Playgroud)
非常遗憾地依赖于UIApplication.sharedApplication()扩展无法访问的内容.
所以我的问题是:我如何在Today扩展中安排本地通知?
有趣的是,我可以使用我的应用程序和我的扩展程序之间共享的代码创建一个框架,在该框架中我可以调用:
func schedule() {
// ...
let settings = UIUserNotificationSettings(forTypes: .Sound | .Alert, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
// ...
UIApplication.sharedApplication().scheduleLocalNotification(notification)
// ...
}
Run Code Online (Sandbox Code Playgroud)
如果我然后从我的扩展中导入该框架并调用schedule()我得到此输出:
Failed to inherit CoreMedia permissions from 13636: (null)
Attempting to schedule a local notification <UIConcreteLocalNotification: 0x7feaf3657a00>{fire date = Saturday, November 1, 2014 at 1:01:48 PM Western European Standard Time, time zone = (null), repeat interval = 0, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Saturday, …Run Code Online (Sandbox Code Playgroud) notifications cocoa-touch ios uilocalnotification ios8-today-widget
我正在使用NSURLSessionDownloadTask对象NSURLSession允许用户在应用程序处于后台/设备锁定状态时下载文档.我还想告知用户个人下载已通过本地通知完成.
为此,我在-URLSession:downloadTask:didFinishDownloadingToURL:下载任务委托方法中触发本地通知,但是我想知道是否有更好的地方添加触发通知的代码,因为Apple解释它的方式,下载任务将传递给系统,从中我得出的是,一旦(或不久之后)应用程序背景化,下载任务的代理将不会再调用这些代理.
我的问题:添加触发本地通知的代码的最佳位置是什么?有没有人在他们的应用程序中添加这种功能有任何经验?
objective-c ios uilocalnotification nsurlsession nsurlsessiondownloadtask
我想在添加新通知时从NotificationCenter中删除所有以前的本地通知.但它在iOS9.0和更低版本中工作,但在iOS 10中它会触发多个本地通知.所以似乎cancelAllLocalNotifications没有清除通知.
代码在iOS10中成功编译.
UIApplication.shared.cancelAllLocalNotifications()
Run Code Online (Sandbox Code Playgroud) 我有一个包含多个本地通知的应用.当我尝试清除所有已发送的通知时,我称之为此removeAllDeliveredNotifications方法.它工作正常,直到ios 11.1.在ios 11.2以上,预期这是行不通的.通知仍保留在通知中心.有人可以帮我解决这个问题.
提前致谢.
我一直在尝试将我的(本地和推送)通知更新为通信通知。
\n当用户收到来自其朋友之一的通信事件时,我希望显示的通知包含该朋友的个人资料图片。就像新的 iMessage 应用程序一样。
\n观看专门的 WWDC2021 会议后,我向我的 SwiftUI 应用程序添加了 Siri Intent:
\n// I correctly added the StartCallIntent to both my app\'s Info.plist and the Siri Intent extension.\n<array>\n <string>INStartCallIntent</string>\n</array>\nRun Code Online (Sandbox Code Playgroud)\n并尝试使用以下内容更新我的通知流程:
\n// I correctly added the StartCallIntent to both my app\'s Info.plist and the Siri Intent extension.\n<array>\n <string>INStartCallIntent</string>\n</array>\nRun Code Online (Sandbox Code Playgroud)\n然后,返回的信息UNNotificationContent将被处理为显示为推送通知或本地通知。
虽然上面的代码不会崩溃并且似乎/工作/,但通知看起来没有任何不同。\n使用调试器查看,已_UNNotificationCommunicationContext初始化,但是:
_displayName为零_recipients为空(如预期)_contentURL为零_attachments是空的sender被设置为UNNotificationContact一个\nhandle& …apple-push-notifications wwdc uilocalnotification swift ios15
ios ×8
objective-c ×3
cocoa-touch ×2
swift ×2
default ×1
ios10 ×1
ios15 ×1
ios5 ×1
iphone ×1
nsurlsession ×1
preferences ×1
wwdc ×1