标签: uilocalnotification

如何为UILocalNotification添加声音?

我已经为我的应用程序完成了基本通知.我想在我的通知中添加声音效果.

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)

如何添加音效?

ios uilocalnotification

12
推荐指数
1
解决办法
2万
查看次数

安排本地通知的编号

我正在制作一个iPhone应用程序,我已经实现了本地通知的概念,提醒用户服用药物.

但在iOS中,我们一次不能安排超过64个通知.但是我在数据库中有许多日期时间条目.我如何安排超过64个通知?

cocoa-touch ios uilocalnotification

11
推荐指数
2
解决办法
9974
查看次数

iOS 5:默认情况下,我可以在"通知中心"中安装我的应用程序吗?

我在App Store中有一个iPad应用程序,其逻辑很大程度上依赖于本地通知.换句话说,应用程序内发生的很多事情都是由委托方法应用程序didReceiveLocalNotification触发的.

随着今天发布的iOS 5,我发现可以通过"设置""在通知中心"或"不在通知中心"放置应用程序.到目前为止,我还没有在新文档中找到任何内容,但是我希望有一种方法可以将我的应用程序默认设置为"In Notification Center"(甚至可能将Sounds设置为活动状态,通知类型设置为Alert)除了向新用户明确说明他们下载并安装我的应用程序后,他们必须手动选择该应用程序为"在通知中心".

任何人都知道这是否可行?似乎由于应用程序可以注册本地通知,因此默认情况下它应该能够接收它(无论它是否在新的通知中心中显示警报或项目).提前致谢.

notifications default preferences uilocalnotification ios5

11
推荐指数
1
解决办法
4081
查看次数

如何从自定义类创建和取消唯一的UILocalNotification?

目前我有一个带闹钟的计时器(本地通知).

我想从这段代码创建一个计时器类来创建多个计时器和通知(最多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所以我可以取消正确的.

提前致谢.

objective-c ios uilocalnotification

11
推荐指数
1
解决办法
1万
查看次数

如何访问默认iOS声音以将其设置为通知声音?

如何将默认iOS声音(三音,钟声,玻璃,号角,贝尔,电子...)设置为本地通知声音?

我创建了本地通知,一切正常,但默认声音(三音).我想使用Chime或其他

我只知道如何使用我自己的声音文件:

localNotif.soundName = @"sound.wav";
Run Code Online (Sandbox Code Playgroud)

iphone notifications objective-c ios uilocalnotification

11
推荐指数
1
解决办法
2万
查看次数

从Today扩展中调度本地通知

我正在创建一个包含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

11
推荐指数
3
解决办法
3311
查看次数

通过NSURLSession/NSURLSessionDownloadTask下载完成时发送本地通知

我正在使用NSURLSessionDownloadTask对象NSURLSession允许用户在应用程序处于后台/设备锁定状态时下载文档.我还想告知用户个人下载已通过本地通知完成.

为此,我在-URLSession:downloadTask:didFinishDownloadingToURL:下载任务委托方法中触发本地通知,但是我想知道是否有更好的地方添加触发通知的代码,因为Apple解释它的方式,下载任务将传递给系统,从中我得出的是,一旦(或不久之后)应用程序背景化,下载任务的代理将不会再调用这些代理.

我的问题:添加触发本地通知的代码的最佳位置是什么?有没有人在他们的应用程序中添加这种功能有任何经验?

objective-c ios uilocalnotification nsurlsession nsurlsessiondownloadtask

11
推荐指数
1
解决办法
1946
查看次数

cancelAllLocalNotifications在iOS10中不起作用

我想在添加新通知时从NotificationCenter中删除所有以前的本地通知.但它在iOS9.0和更低版本中工作,但在iOS 10中它会触发多个本地通知.所以似乎cancelAllLocalNotifications没有清除通知.

代码在iOS10中成功编译.

UIApplication.shared.cancelAllLocalNotifications()
Run Code Online (Sandbox Code Playgroud)

ios uilocalnotification swift ios10

11
推荐指数
2
解决办法
6636
查看次数

UNUserNotificationCenter removeAllDeliveredNotifications在ios 11.2中不起作用

我有一个包含多个本地通知的应用.当我尝试清除所有已发送的通知时,我称之为此removeAllDeliveredNotifications方法.它工作正常,直到ios 11.1.在ios 11.2以上,预期这是行不通的.通知仍保留在通知中心.有人可以帮我解决这个问题.

提前致谢.

ios uilocalnotification unnotificationrequest

11
推荐指数
1
解决办法
1294
查看次数

iOS 15 通讯通知图片未显示

我一直在尝试将我的(本地和推送)通知更新为通信通知。

\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>\n
Run 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>\n
Run Code Online (Sandbox Code Playgroud)\n

然后,返回的信息UNNotificationContent将被处理为显示为推送通知或本地通知。

\n

虽然上面的代码不会崩溃并且似乎/工作/,但通知看起来没有任何不同。\n使用调试器查看,已_UNNotificationCommunicationContext初始化,但是:

\n
    \n
  • _displayName为零
  • \n
  • _recipients为空(如预期)
  • \n
  • _contentURL为零
  • \n
  • _attachments是空的
  • \n
  • sender被设置为UNNotificationContact一个\n
      \n
    • handle& …

apple-push-notifications wwdc uilocalnotification swift ios15

11
推荐指数
1
解决办法
5591
查看次数