Basically creating a mobile app using phonegap/cordova and jquery mobile, I need to land user on a particular page from status bar notification but it shows default page for a while and go to the other page (I want to show) and ends up with default page loaded again.Here is my code:
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="width=device-width, user-scalable=no">
<link rel="stylesheet" href="css/jquery.mobile-1.4.5.min.css" />
<link rel="stylesheet" href="css/style.css" />
<title>App name</title>
</head>
<body>
<!--***************************Start Welcome Page*********************************** -->
<div data-role="page" data-theme='b' id="welcome" class="demo-page">
<div data-role="header" data-position="fixed" data-tap-toggle="false" data-theme='b'>
<h1>App name</h1>
</div>
<div data-role="content">
content here
</div>
<div data-role="footer" data-theme='b' data-position="fixed" data-tap-toggle="false" class="footer">
</div>
</div>
<!--***************************End of Welcome page********************************************-->
<!--***************************Start Login Page*********************************** -->
<div data-role="page" data-theme='b' id="login" class="demo-page">
<div data-role="header" data-position="fixed" data-tap-toggle="false" data-theme='b'>
<h1>App name</h1>
</div>
<div data-role="content">
content here
</div>
<div data-role="footer" data-theme='b' data-position="fixed" data-tap-toggle="false" class="footer">
</div>
</div>
<!--***************************End Login Page*********************************** -->
<!--***************************Start chat Page*********************************** -->
<div data-role="page" data-theme='b' id="chat" class="demo-page">
<div data-role="header" data-position="fixed" data-tap-toggle="false" data-theme='b'>
<h1>App name</h1>
</div>
<div data-role="content">
content here
</div>
<div data-role="footer" data-theme='b' data-position="fixed" data-tap-toggle="false" class="footer">
</div>
</div>
<!--***************************end chat Page*********************************** -->
<script type="text/javascript" src="cordova.js"></script>
<!-- Jquery mobile -->
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/jquery.mobile-1.4.5.min.js"></script>
<!-- Jquery mobile -->
<script type="text/javascript" src="js/PushNotification.js"></script>
<script src="js/main.js"></script>
</body>
</html>
Javascript
function onNotification(e) {
switch( e.event )
{
case 'registered':
break;
case 'message':
if (e.foreground)
{ // Status bar notification if app is in foreground
navigator.notification.beep(1);
}
else
{ // after clicking on status bar notification
$.mobile.changePage('#chat');
}
// notifications when app is open
break;
case 'error':
//$("#app-status-ul").append('<li>ERROR -> MSG:' + e.msg + '</li>');
break;
default:
//$("#app-status-ul").append('<li>EVENT -> Unknown, an event was received and we do not know what it is</li>');
break;
}
}
So it shows welcome page and go to the chat page and again get back to welcome. Tried to set timeout but didn't help.
Any solution?
Please see if it help for you, i have used this code in phonegap android it is working fine.also check the $.mobile.changePage is deprecated from jquery mobile 1.4
onNotificationGCM: function (e) {
var open = false;
switch (e.event) {
case 'registered':
break;
case 'message':
if (e.foreground) {
//App.alertMsg("New message received", "Notification");
}
else {
open = true;
}
break;
case 'error':
// App.alertMsg(e.msg, "NotificationFail");
break;
default:
//App.alertMsg("Unknown", "Notification");
break;
}
if (open) {
$.mobile.pageContainer.pagecontainer('change', "#chat");
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.