标签: nsusernotification

NSUserNotification未显示操作按钮

我正在使用此代码:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
    NSUserNotification *notification = [[NSUserNotification alloc] init];
    [notification setTitle: @"Title"];
    [notification setSubtitle: @"Subtitle"];
    [notification setInformativeText: @"Informative Text"];

    [notification setHasActionButton: YES];
    [notification setActionButtonTitle: @"Action Button"];
    [notification setOtherButtonTitle: @"Other Button"];

    [notification setSoundName: NSUserNotificationDefaultSoundName];

    [notification setDeliveryDate: [NSDate dateWithTimeIntervalSinceNow: 10]];
    [[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification: notification];
}
Run Code Online (Sandbox Code Playgroud)

我得到了,但没有失败,

在此输入图像描述

没有操作按钮或其他按钮.

cocoa osx-mountain-lion nsusernotification

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

从通知中心删除应用程序

嘿,我正在玩一个小的可可应用程序并在Mountain Lion中使用新的Notification Center API.但是,我的应用程序现在存在于通知中心设置中,以及日历,消息等.

因为只是我在玩,我希望它现在从列表中消失,但我无论如何都找不到它,尝试了几件事,拖出来,按住alt +右键等等.有谁知道填充该列表的(可能是)plist位于何处?

macos osx-mountain-lion nsusernotification

20
推荐指数
5
解决办法
3万
查看次数

NSUserNotificationCenter解除通知

我正在尝试将新的Mountain Lion NSUserNotificationCenter用于我的应用程序(实际上并不太难).发布通知就像魅力一样

NSUserNotification *userNotification = [[NSUserNotification alloc] init];
userNotification.title = @"Some title";
userNotification.informativeText = @"Some text";

[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:userNotification];
Run Code Online (Sandbox Code Playgroud)

但是,一旦应用获得焦点,我想解除屏幕上的所有通知.就像新的消息应用程序一样.在后台接收新消息时,会显示通知.当应用程序再次变为活动状态时,这些应用程序将自动关闭并从屏幕和通知中心消失.

为了复制这个,我已经为NSApplicationDidBecomeActiveNotification通知注册了一个方法,该方法也被成功调用.我在那里打电话[NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications].

但是,这会导致删除通知中心中收集的通知,同时仍显示右上角显示的相应"气泡".

迭代所有已发送的通知并逐个删除它们具有完全相同的效果,scheduleNotification而不是使用deliverNotification.

我是唯一遇到此问题的人,还是我错过了以编程方式解除屏幕上部分和通知中心部分通知的内容?

cocoa nsnotificationcenter osx-mountain-lion nsusernotification

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

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

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

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

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

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

在此输入图像描述

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

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

macos notifications objective-c nsusernotification nsusernotificationcenter

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

Mac Mountain Lion从CLI应用程序发送通知

如何从命令行应用程序向通知中心发送通知?到目前为止我的尝试编译和运行,但没有成功通知我.

#import <Cocoa/Cocoa.h>

int main(int argc, const char * argv[]) {
    NSLog(@"Running notifications");

    NSUserNotification *note = [[NSUserNotification alloc] init];
    [note setTitle:@"Test"];
    [note setInformativeText:@"Woot"];

    NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
    [center scheduleNotification: note];

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

我然后编译如下:

clang -framework cocoa /tmp/Notes.m
Run Code Online (Sandbox Code Playgroud)

我明白了

 2012-07-29 16:08:35.642 a.out[2430:707] Running notifications
Run Code Online (Sandbox Code Playgroud)

作为输出,但没有通知:(

这是一个因素吗?

cocoa objective-c nsnotificationcenter osx-mountain-lion nsusernotification

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

NSUserNotification的风格

NSUserNotification如果用户将我的应用的通知样式设置为系统首选项中的"警报",则A 仅显示操作按钮.我可以以某种方式将我的应用程序的样式设置为默认值,而不是依靠用户手动选择它吗?

macos osx-mountain-lion nsusernotification

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

如何实现iOS 10的推送通知[目标C]?

任何人都可以帮我实现iOS 10的推送通知,因为我已经实现了以下代码,但仍然遇到问题:

#define SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0"))
{
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
        if(!error){
            [[UIApplication sharedApplication] registerForRemoteNotifications];
        }
    }];
}
else {
    // Code for old versions
}
Run Code Online (Sandbox Code Playgroud)

我收到错误提示

未知的接收器UIUserNotificationCenter

先感谢您!

objective-c push-notification ios nsusernotification appdelegate

13
推荐指数
2
解决办法
6378
查看次数

应用程序可以在通知中心使用警报和横幅吗?

我正在创建一个Mac OS X应用程序来使用Notification Center.某些通知应保留在屏幕上,直到用户与其进行交互,其他通知应在显示后立即消失.

NSUserNotificationAlertStyle关键的和不断变化的系统首选项允许标语和警示之间变化.但是,两种方法都会更改从我的应用程序发送的所有通知.

我可以发送一些通知作为提醒而其他通知作为横幅吗?如果是这样,怎么样?

macos cocoa nsusernotification

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

NSUserNotification - 小牛队和自定义图像

在10.9中,NSUserNotification支持一个新属性"contentImage",它允许在通知本身中使用图形.我真的希望有一种方法来篡改iTunes的通知屏幕,所以看起来好像发件人/捆绑应用程序图标是自定义的.

在此输入图像描述

但似乎该属性只允许我正在寻找的子集,而contentImage属性只能处理图像:

在此输入图像描述

关于变通方法的任何想法?

icons objective-c nsusernotification

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

Swift和NSUserNotification - 没有横幅或警报,但会静默添加到通知列表中

我正在学习Swift,并希望将简单的用户通知显示为测试.
我的构建成功,但没有显示横幅,而是将通知静默添加到通知列表中.我已经验证了"请勿打扰"已关闭,我在AppleScript中尝试了同样的功能,并且在使用NSUserNotificationAlertStyle我的应用程序的info.plist中的代码时,我尝试了一次成功的非静音警报(不是横幅) ).
但是,这只发生过一次.

我用Swift文件和没有故事板创建了一个新项目.我的AppDelegate.swift包含

import Cocoa

class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet weak var window: NSWindow!


    func applicationDidFinishLaunching(aNotification: NSNotification?) {
        var notification:NSUserNotification = NSUserNotification()
        notification.title = "Title"
        notification.subtitle = "Subtitle"
        notification.informativeText = "Informative text"

        notification.soundName = NSUserNotificationDefaultSoundName

        notification.deliveryDate = NSDate(timeIntervalSinceNow: 5)
        var notificationcenter:NSUserNotificationCenter = NSUserNotificationCenter.defaultUserNotificationCenter()
        if let notificationCenter = NSUserNotificationCenter.defaultUserNotificationCenter() {
            notificationcenter.scheduleNotification(notification)
        }
    }

    func applicationWillTerminate(aNotification: NSNotification?) {
        // Insert code here to tear down your application
    }


}
Run Code Online (Sandbox Code Playgroud)

而且我的info.plist不包含NSUserNotificationAlertStyle前面提到的内容,因为对于横幅来说这不是必需的,我相信.

最后,是的,应用程序"测试"(因为我已经命名它)被设置为显示横幅,因此. 通知系统面板的屏幕截图
总结:我的应用程序成功发出通知,这些通知将添加到通知列表中,但不会显示为横幅.(我使用的是OS X Yosemite 10.10.我希望这个问题与测试版无关)

notifications silent nsnotificationcenter nsusernotification swift

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