• [转]How to open specific page in the application by clicking on the notification


    本文转自:https://github.com/phonegap-build/PushPlugin/issues/213

    问:Hello, I would like to know how can I open a specific page in the application by clicking on the notification

    答:

    Here you have this piece of code (from my app) outside "devide ready" to recieve the push including the extra value. This works for me fine in ios and android (I can't tested it in wp8 becuse is not merged into build service until now)

        //************************************  OUTSIDE DEVICE READY
        // handle APNS notifications for iOS
        function onNotificationAPN(e) {
        // storage the e.id value  (the extra value sent in push notification)
        window.localStorage.setItem("push_que", e.id);
        var push_que=e.id;
        // if the push notification is coming inline
        if (e.foreground=="1")
        {
       // storage the e.numero value  (the extra value sent in push notification)
        window.localStorage.setItem("push_que", e.id);
        var push_que=e.id;
       /// some code here to open a message  if a new push is recieved inline
        ;}
        if ( event.alert )
        {
        navigator.notification.alert(event.alert);
        }
        if ( event.sound )
        {
        var snd = new Media(event.sound);
        snd.play();
        }
        if ( event.badge )
        {
        pushNotification.setApplicationIconBadgeNumber(successHandler, errorHandler, event.badge);
        }
        }
    
        // handle GCM notifications for Android
        function onNotificationGCM(e) {
    
                    switch( e.event )
                    {
                         if (e.foreground)
                         {
        //  if the push is recieved inline
       //  storage the value of  playoad.id,  the extra value sent by push
        window.localStorage.setItem("push_que", e.payload.id);
        var push_que=e.payload.id;
    
        }
        else
        {
        // otherwise we were launched because the user touched a notification in the notification tray
    
        if (e.coldstart)
        {
      //  storage the value of  playoad.numero, the extra value sent by push
    window.localStorage.setItem("push_que", e.payload.id);
    
    }
    else
    {
      //  storage the value of  playoad.numero, the extra value sent by push
    window.localStorage.setItem("push_que", e.payload.id);
    
    }
    }
    
    
                        break;
    
                        case 'error':
    
                        break;
    
                        default:
    
                        break;
                    }
                }
    
    
    
    
    
    
        //********************************** END OUTSIDE DEVICE READY
    
  • 相关阅读:
    Java高级部分--工具类(1)
    Javascript 与正则表达式
    Java基础部分--面向对象基础(1)
    Java基础部分--面向对象高级特性(2)
    持久层框架--hibernate(4)
    持久层框架--hibernate(3)
    持久层框架--hibernate(2)
    python常见面试题
    单元测试之写用例(全局变量,异常处理,断言)
    jmeter安装踩坑记录
  • 原文地址:https://www.cnblogs.com/freeliver54/p/5366587.html
Copyright © 2020-2023  润新知