如何点击推送通知打开一个 ios 应用程序? [英] How to open an ios Application on Tap of Push Notification?

查看:100
本文介绍了如何点击推送通知打开一个 ios 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以知道如何在点击通知时打开 ios 应用程序.或者当我们滑动通知图标(以防 iphone 被锁定时)?

May i know, how to open an ios application, on tapping on notification. Or when we swipe an icon (in case when iphone is locked.) of notification?

有人可以帮我吗?

推荐答案

当通知进来时,操作系统会处理点击通知时的行为.不管它是否由 3rd 方发送,如果它正在发送通过APNS,它将打开应用程序并在applicationDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions :

The OS handles the behavior when tapping the notification as it comes in. Doesn't matter if it is sent by a 3rd party or not, if it is going through APNS, it will open the application and inside applicationDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    if (launchOptions != nil) {
         // Launched from push notification
         NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    }
}

如果应用程序恰好在通知进入时已经打开,操作系统将触发委托方法:

If the app happens to be already open when the notification comes in the OS will fire the delegate method:

 - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary *)userInfo {   
     // Do something
}

这篇关于如何点击推送通知打开一个 ios 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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