I have a cordova ios app. I use the UUID frequently in my app but now its not working it gets stuck at the alert that displays it.
onDeviceReady: function() {
alert("On device Ready"); // Hits this and thats it
alert(device.window.uuid); //does not display this and does not go on
app.receivedEvent('deviceready');
},
as well as when I do:
alert(device.window.uuid);
var pushNotification = window.plugins.pushNotification;
Try this:
alert(device.uuid);
http://docs.phonegap.com/en/3.3.0/cordova_device_device.md.html#device.uuid
If that doesn't work and you are building locally, make sure to run:
cordova plugin add org.apache.cordova.device
Related
What I am doing
I am creating a web form that is being used as a QR code to open an application installed in an android / IOS phone. When the user scans the QR code the phone shall run the web form and the web form will check if the application is installed inside the phone, if the application is installed, the web form will open the application, if not it will open the google play store/app store web page based on which OS system is being used.
My problem
Right now my problem is that I do not know what is the name/id of the application to trigger/open it, the only thing I about the app know is that it is called Rymtime inside the setting and also the home screen. The application's google play store link is at here and here for the app store.
PS. I do not own/create the application and do not have any access to modify its code.
What I have tried
I have tried to put its name directly into the code:
window.location = "Rymtime://";
I have also tried to put the "id" thingy found inside its google play store website "www...id=com.time2clock.wai.timeemployee"
window.location = "com.time2clock.wai.timeemployee://";
My Code
I created my code based on this stack overflow question.
Below is my code:
<body>
...
<button name="data1" type="button" onclick="getOS()">Click</button> //I use button to test out the function
...
</body>
<script type="text/javascript">
function getOS() {
var userAgent = window.navigator.userAgent,
platform = window.navigator.platform,
windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'], //as I do not own an Iphone I use this to test out the IOS part
iosPlatforms = ['iPhone', 'iPad', 'iPod'],
os = null;
if (iosPlatforms.indexOf(platform) !== -1) {
ios();
} else if (windowsPlatforms.indexOf(platform) !== -1) {
ios(); //as I do not own an Iphone I use this to test out the IOS part
} else if (/Android/.test(userAgent)) {
android();
}
}
function ios() {
setTimeout(function () { window.location = "https://apps.apple.com/my/app/rymtime/id1447217174"; }, 25);
window.location = "Rymtime://"; //I do not test this part because I do not own an Iphone an I am using window to see if the code is being executed, I only check if the website above is runned
}
function android() {
setTimeout(function () { window.location = "https://play.google.com/store/apps/details?id=com.time2clock.wai.timeemployee"; }, 25);
window.location = "Rymtime://"; //The application is not executed thus it redirect to the play store page.
}
</script>
Btw is the location of an application installed inside a phone the same as the others? Like this:
somefile\somefile\packageName
Or something like this:
Username(differ)\somefile\somefile\packageName
Thanks.
I am not sure what it is for IOS but I found out that I can just add &launch=true at the end of the URL of the application's google play store page to launch the app if it is installed.
i have problem with handling OneSignal pushNotification in cordova app. My purpose is open display page from any controllers, every page has specific controller. Whenever notification come will do same thing, open display page. My code is here :
index.html
function onDeviceReady() {
document.removeEventListener('deviceready', onDeviceReady, false);
var notificationOpenedCallback = function(jsonData) {
//do some thing
};
window.plugins.OneSignal
.startInit("xxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxx")
.handleNotificationOpened(notificationOpenedCallback)
.endInit();
}
controller
app.controller('startController', function ($scope, $http) {
var notificationOpenedCallback = function (jsonData) {
$scope.myNavigator.pushPage('form/displaypage.html');
};
window.plugins.OneSignal //get error : Uncaught TypeError: Cannot read property 'OneSignal' of undefined
.startInit("xxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxx)
.handleNotificationOpened(notificationOpenedCallback)
.endInit();
});
How to put windos.plugins.OneSignal in controllers?
For cordova apps, you need to add the OneSignal plugin first. In the terminal, at the root of your cordova application, do
cordova plugin add onesignal-cordova-plugin
If you want to save this plugin to your config.xml, add the --save flag to the end of the command. This comes in handy if you're using shared version control.
This will install and register the plugin. You should then rebuild the project and try again on your device.
Further information about setup with the Cordova SDK can be found here
Trying to authenticate users on my ionic application through an external service and I need to use cordovas In app browser! The code works perfectly on android however on iOS the "loadstop" event never fires and thus, the browser never redirects itself back to the application. The code I have looks like this:
$rootScope.$on('$cordovaInAppBrowser:loadstop', function (e, event) {
console.log('inappbrowser loaded', event);
var regex = /* regex to determine if url is correct redirected url */
var res = regex.test(event.url);
alert('loaded: ' + event.url);
alert('regex result: ' + res);
if(res === true) {
$cordovaInAppBrowser.close();
}
});
if(okta) {
if (typeof window.localStorage.msRefreshToken === 'undefined') {
document.addEventListener('deviceready', function () {
$cordovaInAppBrowser.open('urlforExternalservicehere', '_blank', options);
}, false);
} else {
TokenStore.refreshAccessToken();
}
}
when the code is run no alert appears on the screen. Also, once the app has reached the external service and the username of the user is entered, it is then redirected to another url, which the user will then use another set of credentials to authenticate against. This in turn returns a token for the application to authenticate use.
Thus, in a perfect iOS world where it matches the current android experience, the loadstop event fires three times, and the third time the "loadstop" event would fire and the regex would return true and close the in app broswer.
If I need to supply more code to help solve this issue please let me know!
Cordova Version: 4.2.0
Ionic: 1.4.5
iOS: 8 and 9
Using NgCordova for Cordova functionality
UPDATE: when running the application on an emulator and checking the console logs, I find this error:
Error: Module cordova-plugin-inappbrowser.inappbrowser does not
exist., http://10.117.1.46:8100/cordova.js, Line: 1402
I have the plugin installed so I don't know how its missing the plugin. Does anyone have a remedy for this? Thanks!
iabRef = window.open('http://XYZ.php', '_blank', 'location=no,toolbar=no');
iabRef.addEventListener('loadstart', iabLoadStart);
iabRef.addEventListener('loadstop', iabLoadStop);
iabRef.removeEventListener('loaderror', iabLoadError);
iabRef.addEventListener('exit', iabClose);
iabRef.addEventListener('loadstart', function(event) {
if (event.url.match("mobile/close")) {
iabRef.close();
window.location = 'index.html';
}
}
);
Problem was my iOS platform wasn't latest.
So when you developing apps using cordova make sure your platform versions and plugins are up-to date with OS upgraded.
So all I had to do is
Removing iOS platform.
cordova platform rm ios
Adding iOS platform - Latest Version
cordova platform add ios
Removing the plugin cordova-plugin-inappbrowser
cordova plugin remove cordova-plugin-inappbrowser
Adding the plugin cordova-plugin-inappbrowser - Latest Version
cordova plugin add cordova-plugin-inappbrowser
I have a hybrid application with supported environment on iOS, Android, Blackberry, Windows.
The application is working perfectly fine on Development Server, but when I move the same application to Production Server, the Windows version stops working (all other platforms are working fine)
The application loads and shows the RSS Feed, however, the jquery panel menus, jquery nivo sliders etc are not loading, the application also fails to resize itself according to the screen size. So I have a feeling that the JQuery elements are being blocked/stopped on Windows Platform somehow.
Visual Studio is showing a lot of exceptions, but I believe none of them is fatal. log available here
Application Code:
function wlCommonInit() {
//First Landing Page
currentPage = "Public/News/html/news.html";
currentJs = [ "Public\\News\\js\\news.js","Public\\News\\js\\jquery.nivo.slider.js"];
//Connect WL Server to get User Preference
WL.Client.connect({onSuccess: onConnectSuccess, onFailure: onConnectFailure});
if ((WL.Client.getEnvironment() == "windowsphone8") || (WL.Client.getEnvironment() == "android"))
{
document.addEventListener('deviceready', function() {
document.addEventListener('backbutton', handleBackButton);
});
}
eventCall();
$(".logout").hide();
// lock icon - student services
$(".student .ui-collapsible-heading-toggle").css({
'background-image' : 'url(images/lock-red.png)',
'background-repeat' : 'no-repeat',
'background-position' : ''+lockdir+''
});
// lock icon - employee services
$(".employee .ui-collapsible-heading-toggle").css({
'background-image' : 'url(images/lock-red.png)',
'background-repeat' : 'no-repeat',
'background-position' : ''+lockdir+''
});
// service item hover
$('#scrollableContent').on('click','li', function() {
$('#scrollableContent li').css({background: 'transparent'});
$(this).removeClass('ui-body-inherit');
$(this).css({background: '#554e46'});
$(this).removeClass("ui-bar-" + theme);
$(this).css({background: ''});
$(this).removeClass('ui-bar-a ui-bar-b ui-bar-c ui-bar-d ui-bar-e');
$(this).addClass("ui-bar-" + theme);
});
//for menu swiper
swiper();
//for push notification
if (WL.Client.Push) {
WL.Client.Push.onReadyToSubscribe = function() {
WL.Client.Push.registerEventSourceCallback("myPush", "PushAdapter",
"PushEventSource", pushNotificationReceived);
};
}
$("#apppage").show();
}
I have tried checking the error by switching on the HTTP trace for the value, complete log available here
I figured out that some delay due to HTTPS encryption/processing allowed some other procedure calls to be made even before WL.Client Connect completed its execution.
What I did as a work around was to delay other calls so as to ensure that WL.Client Connect completes before any other calls are executed.
I am using this plugin and trying to trigger local notification for my Cordova iOS app with Local notifications plugin.
I dd following steps:
Installed plugin: cordova plugin add de.appplant.cordova.plugin.local-notification#0.7.7
Updated config.xml: gap:plugin name="de.appplant.cordova.plugin.local-notification"
Added the following JavaScript in head tag for
index.html
plugin.notification.local.promptForPermission(function (granted) {
alert("promptForPermission: "+granted);
});
plugin.notification.local.hasPermission(function (granted) {
alert("hasPermission: "+granted);
});
Have a button in index.html to create a local notification after 5 secs.
Code for that looks like this:
function setLocalNotification()
{
alert("from setLocalNotification");
var t = new Date();
t.setSeconds(t.getSeconds() + 3);
window.plugin.notification.local.add({
title: 'Scheduled with delay',
message: 'Test Message ',
date: t
});
alert("alert set");
};
I do see a prompt for user's permission and the alert from hasPermission method shows the value as true. But I am still not able to get the actual local notification I am trying to set by clicking a button. I have already updated the APPLocalNotification.m file for the this issue by copying this fix.
I don't see any more errors in the console log but I am still not able to trigger a local notification.
You should check if the device is ready ( document.addEventListener('deviceready', function () {
) and also check if the plugin is correctly added $ cordova plugin ls.
Make sure you have "< script type="text/javascript" src="cordova.js">
" in your html .
Good luck!