警报框按钮重定向

发布于 2024-12-04 05:47:54 字数 96 浏览 0 评论 0原文

我想知道我们是否真的可以将警报框重定向到特定视图。这意味着,当他们单击通知警报上的“查看”时,它会将他们重定向到特定视图,就像弹出的短信通知一样。有关于这是如何工作的任何想法吗?

I would like to know if we can actually redirect the alert box to a specific view. Meaning that when they clicked on "View" which is on the notification alert, it will redirect them to a particular view, just like the text message notification pop up. Is there any idea on how this works?

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

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

发布评论

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

评论(1

两仪 2024-12-11 05:47:54

从您的问题来看,您可能意味着两种类型的警报对话框:

  1. 您提到的通用“警报框”,或 UIAlertView
  2. 警报对话框,当应用程序位于背景(“就像弹出的短信通知”)

我将按顺序处理它们。


首先,如何处理 UIAlertView“查看”按钮的点击。

实现 alertView:didDismissWithButtonIndex: 控制器类中 UIAlertViewDelegate 协议的方法,以及当您init UIAlertView 将其delegate 设置为self。然后,当用户单击标记为“View”的按钮时,执行以下操作:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if([[alertView buttonTitleAtIndex:buttonIndex] isEqualToString:@"View"])
    {
        // take the user to a specific view
    } else { // handle other cases if you have any
    
    }
}

其次,如何处理触发应用程序启动的 UILocalNotification

关于 UILocalNotification状态:

如果通知是警报,并且用户点击操作按钮(或者,如果设备已锁定,则拖动打开操作滑块),则会启动应用程序。在 application:didFinishLaunchingWithOptions: 方法中,应用程序委托可以使用 UIApplicationLaunchOptionsLocalNotificationKey 键从传入的选项字典中获取 UILocalNotification 对象。委托可以检查通知的属性,如果通知在其 userInfo 字典中包含自定义数据,则它可以访问该数据并进行相应的处理。

另一方面,如果本地通知仅标记应用程序图标,并且用户响应启动应用程序,则将调用 application:didFinishLaunchingWithOptions: 方法,但选项字典中不包含 UILocalNotification 对象。

您需要在应用程序委托类的 application:didFinishLaunchingWithOptions: 方法中编写用于处理此启动情况的代码。

如果您在应用程序运行时碰巧收到 UILocalNotification,Apple 文档指出:

如果系统发送通知时应用程序位于最前面并且可见,则不会显示任何警报,不会标记任何图标,并且不会播放任何声音。但是,如果应用程序委托实现了 application:didReceiveLocalNotification: ,则会调用它。 UILocalNotification 实例被传递到此方法中,委托可以检查其属性或访问 userInfo 字典中的任何自定义数据。


编辑:要立即将用户带到特定视图,您可以手动将某些内容推送到 UINavigationController 堆栈(如果您的应用程序通常使用导航控制器运行,则这样做是有意义的),或 呈现一个模态视图控制器。我在那里链接了两者的指南。

From your question, you could mean two types of alert dialogs:

  1. The generic "alert box" you mention, or UIAlertView
  2. A UILocalNotification alert dialog, shown when the application is in the background ("just like the text message notification pop up")

I will address them in order.


First, how to handle a UIAlertView "View" button click.

Implement the alertView:didDismissWithButtonIndex: method of the UIAlertViewDelegate protocol in your controller class, and when you init the UIAlertView set its delegate to self. Then when the user clicks a button marked e.g. "View", do this:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if([[alertView buttonTitleAtIndex:buttonIndex] isEqualToString:@"View"])
    {
        // take the user to a specific view
    } else { // handle other cases if you have any
    
    }
}

Secondly, how to handle a UILocalNotification which triggers an application launch.

Apple docs on UILocalNotification state:

If the notification is an alert and the user taps the action button (or, if the device is locked, drags open the action slider), the application is launched. In the application:didFinishLaunchingWithOptions: method the application delegate can obtain the UILocalNotification object from the passed-in options dictionary by using the UIApplicationLaunchOptionsLocalNotificationKey key. The delegate can inspect the properties of the notification and, if the notification includes custom data in its userInfo dictionary, it can access that data and process it accordingly.

On the other hand, if the local notification only badges the application icon, and the user in response launches the application, the application:didFinishLaunchingWithOptions: method is invoked, but no UILocalNotification object is included in the options dictionary.

You need to write code for handling this launch case in your app delegate class, in the application:didFinishLaunchingWithOptions: method.

IF you happen to get a UILocalNotification while the app is running, Apple docs state:

If the application is foremost and visible when the system delivers the notification, no alert is shown, no icon is badged, and no sound is played. However, the application:didReceiveLocalNotification: is called if the application delegate implements it. The UILocalNotification instance is passed into this method, and the delegate can check its properties or access any custom data from the userInfo dictionary.


EDIT: To take the user to a specific view straight away, you can manually push something onto a UINavigationController stack (if your app usually operates with navigation controllers, it makes sense to do this), or present a modal view controller. I've linked there to guides for both.

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