问题描述
搜索更改 UILocalNotification ...
我发现不可能从另一个对象访问/调用文本/功能,尽管子类化 UILocalNotification应该允许实现方法 overrides > ...更不用说创建访问者来获取/设置关闭" 按钮文本字段了.
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?...
2011/12/21下午12:01
我要问的问题涉及对oop的理解:晚期/早期绑定,动态方法查找以及声明的类型与运行时类型字段和方法处理.
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.
UILocalNotification的子类可以工作...
Subclassing of UILocalNotification does work...
UILocalNotificationExampleSubclass * example = [UILocalNotificationExampleSubclass init];
...并且设备做创建对象,但是类型为UILocalNotification
而不是UILocalNotificationExampleSubclass
.
...and the device does create an object, however, with type UILocalNotification
and not UILocalNotificationExampleSubclass
.
我正在寻找对UILocalNotification.m文件方法的了解.
I'm looking for insight into the UILocalNotification.m file's methods.
如果没有有自己的方法,则什么对象(请命名)接受UILocalNotification的实例,使用其字段,并显示对象 (请输入名称)我们在屏幕上看到了吗?
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?
推荐答案
UILocalNotification
只是用于存储通知信息的存储区.它什么也没做.
A UILocalNotification
is just a storage for the notification's information. It does not perform anything.
此外,您的应用程序不显示通知.另一个过程可以.因此,将UILocalNotification
子类化是没有用的.
Moreover your application does not display the notification. Another process does. So subclassing UILocalNotification
is just useless.
编辑,时间为12月22日UTC + 1:
EDIT at December 22nd, 17:53 UTC+1:
是的,您可以将UILocalNotification
子类化.但是UILocalNotification
是抽象类,并且没有实现其任何属性. alloc
方法被覆盖,因此它返回私有子类UILocalNotification
的实例.这就是为什么您无法实例化UILocalNotificationExampleSubclass
.
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
.
但是,仍然没有指向子类UILocalNotification
的原因,因为当您使用或使用,操作系统副本通知.
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.
该副本存储在系统管理的另一个进程中,该进程使用其自己的私有存储机制. UILocalNotification
只是一堆属性的存储,这些属性注定要进行序列化并将其从应用程序发送到操作系统.
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.
- 如果您的应用程序不在前台,则完全不受我们控制的其他进程将创建警报并显示通知.除了使用
UILocalNotification
类的属性,我们无法以任何方式自定义该警报. - 如果您的应用程序位于前台,则通知将发送回该应用程序,该应用程序将创建
UILocalNotification
的新实例.然后,UIApplication
共享实例将访问其delegate
属性,并检查该委托是否实现.如果是这样,您将获得通知,并且可以对该通知执行任何您想做的事情.例如,您可以选择使用警报视图显示通知.
- 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.
这篇关于可以将UILocalNotification子类化并更改默认值"Close"(关闭).按钮文字和方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!