我正在使用NSUserNotification来显示通知.这工作正常.问题是当您点击通知时:
任何熟悉NSUserNotification的人都可以提供一些指示吗?
notice.m
#import "Notice.h"
@implementation Notice
- (void) notify:(NSDictionary *)message {
NSLog(@"Notification - Show it");
NSUserNotification *notification = [[NSUserNotification alloc] init];
[notification setTitle:[message valueForKey:@"title"]];
[notification setInformativeText:[message valueForKey:@"content"]];
[notification setDeliveryDate:[NSDate dateWithTimeInterval:0 sinceDate:[NSDate date]]];
[notification setSoundName:NSUserNotificationDefaultSoundName];
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
[center scheduleNotification:notification];
}
- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
{
NSLog(@"Notification - Clicked");
notification=nil;
[center removeDeliveredNotification: notification];
}
#pragma mark WebScripting Protocol
+ (BOOL) isSelectorExcludedFromWebScript:(SEL)selector
{
if (selector == @selector(notify:))
return NO;
return YES;
}
+ (NSString*) webScriptNameForSelector:(SEL)selector …Run Code Online (Sandbox Code Playgroud) 我刚刚注意到iTunes的通知图标被专辑封面取代:

它的应用程序图标在标题附近是一个小图标,与我所知道的有点不同:

我只能添加图像作为内容的一部分,而不是应用程序图标.
是否有NSUserNotification我未知的无证API?
macos cocoa itunes nsusernotification nsusernotificationcenter
我正在使用app,用户可以为每日本地通知设置时间,然后我可以选择启用或禁用这些通知.我的问题如何禁用/取消已设置的通知?
在其中一个IF我需要取消通知
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if (indexPath as NSIndexPath).row == 1 && switchiBtn.isOn == false {
return 0.0
}
if (indexPath as NSIndexPath).row == 2 {
if switchiBtn.isOn == false || dpVisible == true {
return 0.0
}
return 216.0
}
if (indexPath as NSIndexPath).row == 3 {
if switchiBtn.isOn == false || dpVisible == true {
return 0.0
}
return 44
}
return 50.0
}
Run Code Online (Sandbox Code Playgroud)
以下是日程安排和按钮的功能,我在这里设置通知.
func scheduleNotif(date: DateComponents, completion: @escaping …Run Code Online (Sandbox Code Playgroud) 我正在尝试从我的python脚本向Mountain Lion发送通知,并对通知的点击做出反应.现在可以完美地发送通知.但是,我无法让Lion在点击后回拨我的剧本.
这就是我的工作.我实现了一个Notification类.该类实例的唯一目的是通过调用提供通知notify().在同一方法中,我将对象设置为app的委托.
import Foundation
import objc
import AppKit
class MountainLionNotification(Foundation.NSObject, Notification):
def notify(self, title, subtitle, text, url):
NSUserNotification = objc.lookUpClass('NSUserNotification')
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
notification = NSUserNotification.alloc().init()
notification.setTitle_(str(title))
notification.setSubtitle_(str(subtitle))
notification.setInformativeText_(str(text))
notification.setSoundName_("NSUserNotificationDefaultSoundName")
notification.setUserInfo_({"action":"open_url", "value":url})
AppKit.NSApplication.sharedApplication().setDelegate_(self)
NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)
def applicationDidFinishLaunching_(self, sender):
userInfo = sender.userInfo()
if userInfo["action"] == "open_url":
import subprocess
subprocess.Popen(['open', userInfo["value"]])
Run Code Online (Sandbox Code Playgroud)
现在我希望applicationDidFinishLaunching_()在点击通知时被调用.不幸的是,从未发生过 我究竟做错了什么?
有没有人设法使用NSUserNotification soundName来处理自定义声音?我试过aif和caf格式44100KHz 16bit 2秒的持续时间.通知会在适当的时间显示,并带有正确的标题和文字,但会播放默认声音而不是我的自定义声音.
声音文件已在应用程序包中正确复制.如果我试试这个声音可以正常工作:
NSSound* sound = [NSSound soundNamed:@"morse.aif"];
[sound play];
Run Code Online (Sandbox Code Playgroud)
但是当我在通知中使用相同的声音时,会播放默认通知声音:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
NSUserNotification* notification = [[NSUserNotification alloc]init];
notification.title = @"Titolo";
notification.deliveryDate = [NSDate dateWithTimeIntervalSinceNow:10];
notification.soundName = @"morse.aif";
[[NSUserNotificationCenter defaultUserNotificationCenter]scheduleNotification:notification];
}
Run Code Online (Sandbox Code Playgroud)
我尝试了无延伸,但没有成功.
notification.soundName = @"morse.aif";
notification.soundName = @"morse2.caf";
notification.soundName = @"morse";
Run Code Online (Sandbox Code Playgroud)
这些都不起作用.
我的应用程序没有签名,也没有沙盒,但我不认为这对用户通知是必要的,除了声音问题,通知工作得很好.
我在OS X上显示一个本地NSUserNotification,代码如下:
NSUserNotification *notification = [[NSUserNotification alloc] init];
[notification setTitle:@"Some Title"];
[notification setHasActionButton:YES];
[notification setActionButtonTitle:@"Snooze"];
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
[center setDelegate:self];
[center scheduleNotification:notification];
Run Code Online (Sandbox Code Playgroud)
我面临的问题是,如果单击通知本身或"操作按钮",我只会收到一条消息,但如果单击"其他"按钮(关闭按钮),我还想执行一些代码.如果NSUserNotification被解除或点击关闭按钮,有没有办法得到通知?userNotificationCenter:didActivateNotification:单击关闭按钮时不会触发NSUserNotificationCenter .
如果这是不可能的,有没有办法在其Reminder应用程序中创建Apple使用的下拉按钮(如果用户持有操作按钮,则会打开一个菜单).
谢谢!
cocoa notifications button nsusernotification nsusernotificationcenter
我正在研究10.8上的示例用户通知,但关键的NSUserNotificationAlertStyle当我将其设置为警报不起作用时,我的应用程序仍然将其显示为横幅,这是通过系统首选项控制它的唯一方法但是如果我想设置默认行为保持警惕的风格?
我正在研究一个快速的os x应用程序,我无法理解userNoticiation/didActivateNotification结构.我查看了文档并搜索了SO但仍然卡住了.我们非常感谢您对以下代码的任何指导:
func notify(message: String, callBack: String) {
println(message)
println(callBack)
var notification:NSUserNotification = NSUserNotification()
notification.title = "New Phone Call"
notification.informativeText = message
notification.actionButtonTitle = "Lookup"
notification.hasActionButton = true
var center:NSUserNotificationCenter = NSUserNotificationCenter.defaultUserNotificationCenter()
center.delegate = self
center.scheduleNotification(notification)
}
func notify (center: NSUserNotificationCenter, didActivateNotification notification: NSUserNotification){
center.delegate = self
println("clicked") //this does not print
}
Run Code Online (Sandbox Code Playgroud)
通知显示完全符合我的要求.单击我定义的"查找"按钮会在第一次单击时将我的应用程序带到前台,但是我希望处理该操作的代码不会触发.
提前致谢.
在撰写这篇文章之前,我对UserNotification Framework进行了大量研究,取代了IOS 10中的UILocalNotification.我也按照本教程学习了有关这一新功能的所有内容:http://useyourloaf.com/blog/local-notifications-with- ios-10 /.
今天我遇到了很多麻烦来实现这些琐碎的通知,因为它是最近的新功能,我找不到任何解决方案(特别是在目标C中)!我目前有2个不同的通知,一个警报和一个徽章更新.
在将我的手机从IOS 10.1升级到10.2之前,我在Appdelegate上发出警报,当用户手动关闭应用程序时,该警报立即被触发:
-(void)applicationWillTerminate:(UIApplication *)application {
NSLog(@"applicationWillTerminate");
// Notification terminate
[self registerTerminateNotification];
}
// Notification Background terminate
-(void) registerTerminateNotification {
// the center
UNUserNotificationCenter * notifCenter = [UNUserNotificationCenter currentNotificationCenter];
// Content
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
content.title = @"Stop";
content.body = @"Application closed";
content.sound = [UNNotificationSound defaultSound];
// Trigger
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats:NO];
// Identifier
NSString *identifier = @"LocalNotificationTerminate";
// création de la requête …Run Code Online (Sandbox Code Playgroud) 有没有办法为每个提供自定义图标NSUserNotification,而不是默认的应用程序徽标?就像iconData参数一样Growl.
我想用这个"某人"的照片来展示"有人刚发布的东西".