wma*_*but 13 cocoa objective-c nsnotificationcenter osx-mountain-lion nsusernotification
如何从命令行应用程序向通知中心发送通知?到目前为止我的尝试编译和运行,但没有成功通知我.
例
#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)
作为输出,但没有通知:(
这是一个因素吗?
小智 18
我发现,NSUserNotificationCenter工作时[[NSBundle mainBundle] bundleIdentifier]返回正确的标识符.所以,我写了一些你可以在https://github.com/norio-nomura/usernotification找到的混合代码
它可以在NSUserNotification没有应用程序包的情况下发送.
| 归档时间: |
|
| 查看次数: |
3517 次 |
| 最近记录: |