【问题标题】:Cordova windows 8 phone WNS push notification and app release process with detailsCordova windows 8 手机 WNS 推送通知和应用发布流程及详细信息
【发布时间】:2015-12-04 11:43:20
【问题描述】:

我正在使用cordova 开发windows phone 应用程序。我需要在这个应用程序中实现推送通知。现在我正在使用下面的插件来推送通知。 https://github.com/phonegap-build/PushPlugin

我创建了一个 Windows 开发者帐户并在此帐户中注册了应用程序。还在 Live Services 站点中创建了客户端 ID、客户端密码。我需要明确说明在 windows 应用程序中添加应用程序身份。

谢谢。

【问题讨论】:

    标签: cordova windows-phone-8 push-notification


    【解决方案1】:

    先添加这个插件https://github.com/phonegap-build/PushPlugin

    将此添加到脚本文件中。

    if(deviceID == "undefined" || deviceID == null || deviceID == "null"){
                pushNotificationVariable = window.plugins.pushNotification;
                var platform = device.platform;
    
                switch(platform){
                    case 'iOS':
                        pushNotificationVariable.register(tokenHandler,errorHandler,{ "badge":"true","sound":"true","alert":"true","ecb":"onNotificationAPN"});
                    break;
                    case 'Android':
                        pushNotificationVariable.register(successHandler,errorHandler,{"senderID":"643203326229","ecb":"onNotification"});
                    break;
                    case 'Win32NT':
                        var channelName = "PUSHChannel";
                        pushNotificationVariable.register(channelHandler, errorHandler, { "channelName": channelName, "ecb": "onNotificationWP8", "uccb": "channelUriHandler", "errcb": "jsonErrorHandler" });
                    break;
                    default:
                        window.localStorage.setItem("DeviceID",device.uuid);
                    break;
                }
    
            }
    

    此代码将在您将该 ChannelURI 发送到 Service 之后返回 ChannelURI,以便他们能够将 Push 发送到 windows phone。

    Try this

    Reference

    在 Mainpage.xaml.cs 中添加这个

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            try
            {
                if (this.NavigationContext.QueryString["NavigatedFrom"] == "Toast Notification") // this is set on the server
                {
                    string navigatedString = this.NavigationContext.QueryString["NavigatedFrom"];
                    this.CordovaView.StartPageUri = new Uri("//www/index.html#navstring=" + navigatedString, UriKind.Relative);
                }
            }
            catch (KeyNotFoundException)
            {
            }
        }
    

    从 javscript 调用 angularjs 函数

    function ajaxResultPost(data, type, res) {
    var scope = angular.element(document.getElementById("MainWrap")).scope();
    scope.$apply(function () {
    scope.updateCustomRequest(data, type, res);
    });
    }
    

    如果你想从 c# 调用 javascript 函数,那么试试这个

    this.CordovaView.Browser.InvokeScript("eval", new string[] { "yourJavascriptFunction(); " });
    

    如何从 C# 调用 JavaScript – Cordova/PhoneGap

    https://cordovablogsblogs.wordpress.com/2015/07/10/how-to-call-javascript-from-c-cordovaphonegap/

    【讨论】:

    • 感谢您的反馈。
    • 现在我收到通知了。我需要在单击通知时导航相应的页面。请帮我。谢谢。
    • 我已经提到了这个解决方案。但我的问题是从不同模块收到的推送通知。当我使用此代码时,URL 被导航。但是我的内容没有加载,因为内容是从 angularJs 函数加载的。我需要知道如何在导航之前调用 angularjs 函数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-28
    • 2014-03-04
    • 1970-01-01
    相关资源
    最近更新 更多