如何在 work light + angularJS 中从推送通知重定向特定页面
How to Redirection particular Page from PushNotification in worklight + angularJS
我在 android/ios 环境中使用 worklight + AngularJs 开发了推送通知,我在两个平台上都获得了成功的通知。
我的应用程序有多个 HTML 页面。每当我从通知栏单击收到的通知时,它都会重定向到默认的 index.html 页面,但我希望它重定向任何其他 (HTML) 内部页面。我还关注了一些与此问题相关的 LINK 但它显示了我们是否在单个 html 文件中有代码。但就我而言,我有多个 HTML,我不知道如何实现这种情况。
我知道你们中的许多人发现这是一个重复的问题,但我认为这种情况有些不同。
下面是我在 main.js
中的广播通知代码
function wlCommonInit(){
angular.element(document).ready(function() {
// Boot up
angular.bootstrap(document, ["myMobile"]);
});
WL.Client.connect({onSuccess: connectSuccess, onFailure: connectFailure});
}
function connectSuccess() {
WL.Logger.debug ("Successfully connected to MobileFirst Server.");
}
function connectFailure() {
WL.Logger.debug ("Failed connecting to MobileFirst Server.");
//1st snippet
WL.SimpleDialog.show("Push Notifications", "Failed connecting to MobileFirst Server. Try again later.",
[{
text : 'Reload',
handler : WL.Client.reloadapp
},
{
text: 'Close',
handler : function() {}
}]
);
}
//2nd snippet. For the 3rd one copy the adapter
//------------------------------- Handle received notification ---------------------------------------
WL.Client.Push.onMessage = function (props, payload) {
WL.SimpleDialog.show("Tag Notifications", "Provider notification data: " + JSON.stringify(props), [ {
text : 'Close',
handler : function() {
WL.SimpleDialog.show("Brodcast Notifications", "Application notification data: " + JSON.stringify(payload), [ {
text : 'Close',
handler : function() {}
}]);
}
}]);
};
下面的代码是我的 angularJS route.js:
angular.module('MyMobile').
config(['$routeProvider', function($routeProvider) {
$routeProvider.
when("/login", {
templateUrl: "partials/login.html",
controller: "loginController"}
).
when("/home/:activePanelId", {
templateUrl: "partials/home.html",
controller: "homeController"}
).
when("/activity", {
templateUrl: "partials/home.html",
controller: "homeController",
activetab: "activity"}
).
when("/messages", {
templateUrl: "partials/home.html",
controller: "homeController",
activetab: "messages"}
).
when("/membership", {
templateUrl: "partials/membership.html",
controller: "membershipController"}
).
when("/documentrequest", {
templateUrl: "partials/documentRequest.html"/*,
controller: "documentRequestController"*/}
).
when("/findprovider", {
templateUrl: "partials/findProvider.html",
controller: "findProviderController"}
).
when("/benefitsearch", {
templateUrl: "partials/benefitSearch.html",
controller: "benefitController"}
).
when("/benefitsearchresults", {
templateUrl: "partials/benefitSearchResults.html",
controller: "benefitController"}
).
when("/medicine", {
templateUrl: "partials/medicine.html",
controller: "medicineController"}
).
when("/ehr", {
templateUrl: "partials/ehr.html",
controller: "ehrController"}
).
when("/preauthorization", {
templateUrl: "partials/preAuthorization.html",
controller: "preAuthorizationController"}
).
otherwise({redirectTo: '/login'});
}]);
注意:当我点击通知栏中的通知时,我想重定向到“/messages”。
为什么必须用 AngularJS 来完成?它也可以通过捆绑在 Worklight 中的简单 jQuery API 使用来完成。在这种情况下没有什么特别的,甚至需要 AngularJS IMO。
无论推送通知如何,请参阅以下示例应用程序如何实现多页面导航。当应用程序捕获推送通知时,同样可以应用:https://www.dropbox.com/s/edn71leo5197i80/multipageexecuteplugin.zip?dl=0
当点击通知栏中的通知时,它会触发 pushNotificationReceived 方法。这是放置处理收到的通知的代码的地方。然后你需要 "return" 到 Angular 范围。因此,使用 location.href 重定向到“#/”+ 请求的页面名称(在我们的例子中是 "messages")。请注意,如果您想在#/messages 页面中使用此通知,您需要将其分配给某个全局变量。
function pushNotificationReceived(props, payload) {
...
location.href = window.location.pathname + "#/messages";
}
我在 android/ios 环境中使用 worklight + AngularJs 开发了推送通知,我在两个平台上都获得了成功的通知。
我的应用程序有多个 HTML 页面。每当我从通知栏单击收到的通知时,它都会重定向到默认的 index.html 页面,但我希望它重定向任何其他 (HTML) 内部页面。我还关注了一些与此问题相关的 LINK 但它显示了我们是否在单个 html 文件中有代码。但就我而言,我有多个 HTML,我不知道如何实现这种情况。
我知道你们中的许多人发现这是一个重复的问题,但我认为这种情况有些不同。
下面是我在 main.js
中的广播通知代码function wlCommonInit(){
angular.element(document).ready(function() {
// Boot up
angular.bootstrap(document, ["myMobile"]);
});
WL.Client.connect({onSuccess: connectSuccess, onFailure: connectFailure});
}
function connectSuccess() {
WL.Logger.debug ("Successfully connected to MobileFirst Server.");
}
function connectFailure() {
WL.Logger.debug ("Failed connecting to MobileFirst Server.");
//1st snippet
WL.SimpleDialog.show("Push Notifications", "Failed connecting to MobileFirst Server. Try again later.",
[{
text : 'Reload',
handler : WL.Client.reloadapp
},
{
text: 'Close',
handler : function() {}
}]
);
}
//2nd snippet. For the 3rd one copy the adapter
//------------------------------- Handle received notification ---------------------------------------
WL.Client.Push.onMessage = function (props, payload) {
WL.SimpleDialog.show("Tag Notifications", "Provider notification data: " + JSON.stringify(props), [ {
text : 'Close',
handler : function() {
WL.SimpleDialog.show("Brodcast Notifications", "Application notification data: " + JSON.stringify(payload), [ {
text : 'Close',
handler : function() {}
}]);
}
}]);
};
下面的代码是我的 angularJS route.js:
angular.module('MyMobile').
config(['$routeProvider', function($routeProvider) {
$routeProvider.
when("/login", {
templateUrl: "partials/login.html",
controller: "loginController"}
).
when("/home/:activePanelId", {
templateUrl: "partials/home.html",
controller: "homeController"}
).
when("/activity", {
templateUrl: "partials/home.html",
controller: "homeController",
activetab: "activity"}
).
when("/messages", {
templateUrl: "partials/home.html",
controller: "homeController",
activetab: "messages"}
).
when("/membership", {
templateUrl: "partials/membership.html",
controller: "membershipController"}
).
when("/documentrequest", {
templateUrl: "partials/documentRequest.html"/*,
controller: "documentRequestController"*/}
).
when("/findprovider", {
templateUrl: "partials/findProvider.html",
controller: "findProviderController"}
).
when("/benefitsearch", {
templateUrl: "partials/benefitSearch.html",
controller: "benefitController"}
).
when("/benefitsearchresults", {
templateUrl: "partials/benefitSearchResults.html",
controller: "benefitController"}
).
when("/medicine", {
templateUrl: "partials/medicine.html",
controller: "medicineController"}
).
when("/ehr", {
templateUrl: "partials/ehr.html",
controller: "ehrController"}
).
when("/preauthorization", {
templateUrl: "partials/preAuthorization.html",
controller: "preAuthorizationController"}
).
otherwise({redirectTo: '/login'});
}]);
注意:当我点击通知栏中的通知时,我想重定向到“/messages”。
为什么必须用 AngularJS 来完成?它也可以通过捆绑在 Worklight 中的简单 jQuery API 使用来完成。在这种情况下没有什么特别的,甚至需要 AngularJS IMO。
无论推送通知如何,请参阅以下示例应用程序如何实现多页面导航。当应用程序捕获推送通知时,同样可以应用:https://www.dropbox.com/s/edn71leo5197i80/multipageexecuteplugin.zip?dl=0
当点击通知栏中的通知时,它会触发 pushNotificationReceived 方法。这是放置处理收到的通知的代码的地方。然后你需要 "return" 到 Angular 范围。因此,使用 location.href 重定向到“#/”+ 请求的页面名称(在我们的例子中是 "messages")。请注意,如果您想在#/messages 页面中使用此通知,您需要将其分配给某个全局变量。
function pushNotificationReceived(props, payload) {
...
location.href = window.location.pathname + "#/messages";
}