标签: nsusernotificationcenter

Mac OS X NSUserNotificationCenter通知获取解雇事件/回调

在我们的应用程序中,我们以警报样式显示通知中心通知.

显示通知工作正常,以及当用户通过单击通知或单击"操作"按钮与通知进行交互时,我们会收到回调.

但是,当用户点击通知中的"其他"按钮时,我们有兴趣获取回调或事件.我看到MAC OS在显示其可用更新对话框时执行此操作.

有关OS X更新可用警报的说明,请参阅此图像:

在此输入图像描述

我已搜查这个在互联网上,以及通过通知中心的文档了这个这个为好.

有没有未记录的API?或一些自定义机制检测点击其他(关闭)按钮?

macos notifications objective-c nsusernotification nsusernotificationcenter

14
推荐指数
1
解决办法
4410
查看次数

NSUserNotification可自定义的应用程序图标?

我刚刚注意到iTunes的通知图标被专辑封面取代:

iTunes通知

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

正常通知

我只能添加图像作为内容的一部分,而不是应用程序图标.

是否有NSUserNotification我未知的无证API?

macos cocoa itunes nsusernotification nsusernotificationcenter

9
推荐指数
1
解决办法
1925
查看次数

检测关闭按钮单击NSUserNotification

我在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

8
推荐指数
0
解决办法
2645
查看次数

Swift NSUserNotificationCenter doActivateNotification无效

我正在研究一个快速的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)

通知显示完全符合我的要求.单击我定义的"查找"按钮会在第一次单击时将我的应用程序带到前台,但是我希望处理该操作的代码不会触发.

提前致谢.

macos nsusernotification nsusernotificationcenter swift

7
推荐指数
1
解决办法
1696
查看次数

NSUserNotificationCenter.defaultUserNotificationCenter()在python中返回None

我想通过python连接到Mountain Lion通知中心.我已经安装了pyobjc,并按照这里这里的说明操作.另请参阅:使用PyObjC与Mountain Lion的通知中心合作

这是我的代码:

import Foundation, objc
import AppKit
import sys

NSUserNotification = objc.lookUpClass('NSUserNotification')
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')

def notify(title, subtitle, info_text, delay=0, sound=False, userInfo={}):
    """ Python method to show a desktop notification on Mountain Lion. Where:
        title: Title of notification
        subtitle: Subtitle of notification
        info_text: Informative text of notification
        delay: Delay (in seconds) before showing the notification
        sound: Play the default notification sound
        userInfo: a dictionary that can be used to handle clicks in your …
Run Code Online (Sandbox Code Playgroud)

python pyobjc nsnotificationcenter osx-mountain-lion nsusernotificationcenter

5
推荐指数
1
解决办法
1090
查看次数

单击显示NSUserNotification additionalActions

additionalActions

在上图中,您可以在OS X上看到两个通知.第一个来自我的应用程序,第二个来自Apple的Reminders.app.在图像中,您可以看到otherButtonTitle"完成"和actionButtonTitle"稍后".

第二个通知,即来自Reminders.app的通知,表现完全不同.它会使鼠标指向下方的这个小箭头指示单击时有更多操作.事实上,你只需要点击一次在"后来",它会给你一对夫妇更多可供选择的方案.

但是,我无法使用相同的行为来处理我的通知.鼠标悬停时我没有得到小箭头,只需点击"稍后"即可显示更多选项(通知只是被解雇).只有在"稍后"按住鼠标按钮时才会显示更多选项,这一点并不明显.

我错过了一些明显的东西吗?如何让我的通知与Reminders.app中的通知完全相同?

macos cocoa nsusernotification nsusernotificationcenter

5
推荐指数
1
解决办法
980
查看次数

有没有办法知道NSUserNotificationCenter中有多少NSUserNotifications?

是否有任何非私密方式可以知道NSUserNotificationCenterMountain Lion 中的通知中心()中有多少通知?不仅是来自我的应用的通知,还来自所有应用.

所以,总结一下,我想要做的是检索这里显示的通知数量: 在此输入图像描述

我试图搜索,但我找不到有关此信息.有任何想法吗?
提前致谢!

macos cocoa objective-c nsusernotification nsusernotificationcenter

3
推荐指数
1
解决办法
609
查看次数

应用程序处于活动状态时,不会显示Swift NSUserNotification

我是OSX开发的新手,我正在创建一个应用程序,当事情发生时触发通知.但是当应用程序是关键应用程序时它没有显示通知,因为它是默认行为.即使应用程序是关键应用程序,我也想展示它们.但是我只找到了用objective-c编写的这个问题的解决方案,但现在我正在使用Swift.我想知道如何用Swift实现它.

nsusernotification nsusernotificationcenter swift osx-yosemite

3
推荐指数
1
解决办法
2425
查看次数

NSUserNotificationCenter未显示通知

我不确定我是否出了问题,但是从我能找到的例子中可以看出来.我写了那个小小的helloworld.

#import <Foundation/Foundation.h>
#import <Foundation/NSUserNotification.h>


int main (int argc, const char * argv[])
{
    NSUserNotification *userNotification = [[NSUserNotification alloc] init];
    userNotification.title = @"Some title";
    userNotification.informativeText = @"Some text";

    [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:userNotification];

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我编译它:

cc -framework Foundation -o app main.m
Run Code Online (Sandbox Code Playgroud)

它编译,我可以执行它,但它不会显示任何东西.由于某些原因,没有任何东西出现.我读到如果应用程序是主要角色,则可能无法显示通知.如何让它显示通知?

nsusernotification nsusernotificationcenter

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

使用回复字段创建通知

如何从带有回复字段的通知中获取输入.我在文档中没有找到任何内容

这是我当前的代码,我需要从用户那里得到什么回复?

#import "AppDelegate.h"

@implementation AppDelegate
@synthesize nTitle;
@synthesize nMessage;

- (IBAction)showNotification:(id)sender{
    NSUserNotification *notification = [[NSUserNotification alloc] init];
    notification.title = [nTitle stringValue];
    notification.informativeText = [nMessage stringValue];
    notification.soundName = NSUserNotificationDefaultSoundName;

    [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
    [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
}
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification{
    return YES;
}

@end
Run Code Online (Sandbox Code Playgroud)

我在哪里可以找到通知中心的最新信息和文档?

cocoa input nsusernotificationcenter osx-mavericks

0
推荐指数
1
解决办法
2007
查看次数