Searching for a way to change the "Close" button text/functionality of a UILocalNotification...
I've found that it's impossible to access/call the text/function from another object, although subclassing UILocalNotification should allow implementation method overrides... not to mention the creation of an accessor to get/set the "Close" button text field.
What do you guys think about this? What would Apple?
Has anyone tried?...
EDIT: 12/21/2011 12:01 PM
The question that I'm asking involves an understanding of oop: late/early binding, dynamic method lookup, and declared type vs. runtime type field and method handling.
Subclassing of UILocalNotification does work...
UILocalNotificationExampleSubclass * example = [UILocalNotificationExampleSubclass init];
...and the device does create an object, however, with type UILocalNotification
and not UILocalNotificationExampleSubclass
.
I'm looking for insight into the UILocalNotification.m file's methods.
If it does not have its own methods, what object (name please) takes an instance of a UILocalNotification, uses its fields, and displays the object (name please) we see on screen?
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, theUIApplication
shared instance will access itsdelegate
property and check if that delegate implementsapplication: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.
来源:https://stackoverflow.com/questions/8580782/possible-to-subclass-uilocalnotification-and-change-default-close-button-text