gpt4 book ai didi

NSUserNotificationCenter 不显示通知

转载 作者:行者123 更新时间:2023-12-05 08:59:16 24 4
gpt4 key购买 nike

我不确定我是否弄错了,但从我能找到的例子来看。我写了那个小小的 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;
}

我编译它:

cc -framework Foundation -o app main.m

它可以编译,我可以执行它,但它不会显示任何内容。由于某些原因,什么也没有呈现。我读到如果应用程序是主要参与者,通知可能不会显示。如何让它显示通知?

最佳答案

设置委托(delegate)并覆盖

- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center 
shouldPresentNotification:(NSUserNotification *)notification {
return YES;
}

关于NSUserNotificationCenter 不显示通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15896348/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com