Re: Exception on launch when clicking on an NSUserNotification
Re: Exception on launch when clicking on an NSUserNotification
- Subject: Re: Exception on launch when clicking on an NSUserNotification
- From: Alex Kac <email@hidden>
- Date: Thu, 26 Feb 2015 22:27:17 -0700
On OS X (this is OS X, not iOS - hence NSUserNotification and not UILocalNotification), when you start an app by tapping on a notification, because you haven’t had a chance yet to register the delegate of the NSUserNotificationCenter (this has nothing to do with NSNotificationCenter), the OS passes in the notification as part of the notification on launch:
> NSApplicationLaunchUserNotificationKey
> The following key is an NSUserNotification object that will be present in the notification userInfo dictionary of the NSApplicationDidFinishLaunchingNotification notification if your app was launched because a user activated a notification in the Notification Center.
>
> Available in OS X v10.8 and later.
Second, as you can see in the printed object below, the length of the strings are:
{ title: "Test" informativeText: "9:55 PM" actionButtonTitle: “Snooze”
What’s not shown above is the identifier - which is a 64 character string, and the sound name which is a 10 character string. I’m pretty sure that’s not more than 1k. And yes, I’ve gone through all the documentation, I’ve gone through EVERY SINGLE property of NSUserNotification in the headers and in the docs to make sure I’m not putting something in there I shouldn’t be.
AND remember - this WORKS if the app is running and it delivers the notification to the - (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification method.
It only fails on startup with the notification in didFinishLaunching.
I do believe there is something I am doing wrong…I just can’t figure out what. In my other reply on this, I also posted my code as well and with the info above, you can see what text I posted. This is why its so frustrating. I am getting no meaningful error, the data I’m giving it - as far as I can tell - is correct.
What I’ll start doing is cutting it down to the basics - no action, no informative text, no sound - and just start from the very very minimum and see what happens…
> On Feb 26, 2015, at 9:12 PM, Graham Cox <email@hidden> wrote:
>
> OK, I may be having a massive misunderstanding about how iOS works (as compared with Mac OS), but the NSUserNotification you post is, as far as I'm aware, completely unrelated to the NSNotification that is passed to -applicationWill/DidFinishLaunching.
>
> The latter is just a notification that the application created internally, and as a convenience passed to its delegate before or after broadcasting it using NSNotificationCenter.
>
> The user notification you post just triggers the notification system. I realise it's pretty confusing with everything being called more or less the same thing, but they are totally different. The userInfo you pass in your user notificaiton will not turn up in the app delegate's did launch notification. (Unless, that is, iOS is documented to do that. Mac OS definitely doesn't).
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden