可以子类化 UILocalNotification 并更改默认“关闭”按钮文本和方法?

发布于 2024-12-22 04:47:42 字数 916 浏览 1 评论 0原文

正在寻找一种方法来更改UILocalNotification“关闭”按钮文本/功能...

我发现它不可能访问/从另一个对象调用文本/函数,尽管子类化 UILocalNotification 应该允许实现方法覆盖...更不用说创建访问器获取/设置“关闭”按钮文本字段。

大家对此有何看法? 苹果会怎么做?

有人尝试过吗?...

编辑:12/21/2011 12:01 PM

我问的问题涉及对 oop: Late 的理解/早期绑定、动态方法查找以及声明类型与运行时类型字段和方法处理。

UILocalNotification 的子类化确实工作...

UILocalNotificationExampleSubclass * example = [UILocalNotificationExampleSubclass init];

...并且设备确实创建一个对象,但是,类型为 UILocalNotification 而不是 UILocalNotificationExampleSubclass

我正在寻找对 UILocalNotification.m 文件方法的深入了解。

如果它没有有自己的方法,那么什么对象(请提供名称)采用 UILocalNotification 的实例,使用其字段,并显示该对象(请提供名称) )我们在屏幕上看到了什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤寂小茶 2024-12-29 04:47:42

UILocalNotification 只是通知信息的存储。它不执行任何操作。

此外,您的应用程序不会显示通知。另一个进程也可以。所以子类化 UILocalNotification 是没有用的。

编辑,12 月 22 日 17:53 UTC+1:

是的,您可以对 UILocalNotification 进行子类化。但是 UILocalNotification 是一个抽象类,它的任何属性都没有实现。 alloc 方法被重写,因此它返回一个私有子类 UILocalNotification 的实例。这就是为什么您无法实例化 UILocalNotificationExampleSubclass

但仍然没有指向子类 UILocalNotification 因为当您使用 -[UIApplication ScheduleLocalNotification:] 或使用 -[UIApplication PresentLocalNotification:],操作系统复制通知。

该副本存储在系统管理的另一个进程中,该进程使用自己的私有存储机制。 UILocalNotification 只是一组属性的存储,这些属性注定要被序列化并从应用程序发送到操作系统。

现在,我们有另一个进程存储所有计划的本地通知并等待通知触发。发生这种情况时,该进程将检查您的应用程序是否位于前台。

  • 如果您的应用程序不在前台,则完全不受我们控制的其他进程将创建警报并显示通知。除了使用 UILocalNotification 类的属性之外,我们无法以任何方式自定义该警报。
  • 如果您的应用程序位于前台,通知将被发送回创建 UILocalNotification 新实例的应用程序。然后,UIApplication 共享实例将访问其 delegate 属性并检查该委托是否实现 应用程序:didReceiveLocalNotification:。如果是这样,您会收到通知,并可以使用该通知执行您想要的任何操作。例如,您可以选择使用警报视图显示通知。

配置和显示警报视图可以这样完成:

- (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
}

我希望这个较长的响应能够回答您的问题,如果我说的是真的

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文