可以将UILocalNotification子类化并更改默认值"Close"(关闭).按钮文字和方法? [英] Possible to Subclass UILocalNotification and Change Default "Close" Button Text and Method?

查看:86
本文介绍了可以将UILocalNotification子类化并更改默认值"Close"(关闭).按钮文字和方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

搜索更改 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的原因,因为当您使用 -[UIApplication presentLocalNotification:] ,操作系统副本通知.

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, 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.

这篇关于可以将UILocalNotification子类化并更改默认值"Close"(关闭).按钮文字和方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆