A UILocalNotification
is just a storage for the notification's information. It does not perform anything.
Moreover your application does not display the notification. Another process does. So subclassing UILocalNotification
is just useless.
EDIT at December 22nd, 17:53 UTC+1:
Yes, you can subclass UILocalNotification
. But UILocalNotification
is an abstract class and none of its properties is implemented. The alloc
method is overridden so it returns an instance of UILocalNotification
, a private subclass. That's why you cannot instantiate UILocalNotificationExampleSubclass
.
But still, there is not point to subclass UILocalNotification
because when you schedule a notification using -[UIApplication scheduleLocalNotification:]
or present the notification immediately using -[UIApplication presentLocalNotification:]
, the operating system copies the notification.
That copy is stored in another process managed by the system, which uses its own private storage mechanism. A UILocalNotification
is just a storage for a bunch of properties that is destined to get serialized and sent from the application to the operating system.
Now, we have that other process storing all the scheduled local notifications and waiting for a notification to fire. When that happens, that process will check if your application is in the foreground.
- If your application is not in the foreground, that other process, which is totally out of our control, will create an alert and display the notification. We cannot customize that alert in any way, except by using the properties of the
UILocalNotification
class.
- If your application is in the foreground, the notification will be sent back to the application that will create a new instance of
UILocalNotification
. Then, the UIApplication
shared instance will access its delegate
property and check if that delegate implements application:didReceiveLocalNotification:
. If it does, you get the notification back and can do anything you want with that notification. For example, you may choose to display the notification using an alert view.
Configuring and displaying the alert view can be done like this:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIAlertView *alertView =
[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Alert", nil)
message:NSLocalizedString(notification.alertBody, nil)
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:NSLocalizedString(@"OK", nil), nil];
[alertView show];
[alertView release]; // unless your project uses Automatic Reference Counting
}
I hope this longer response did answer your question, if what I'm saying is true.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…