Hello I am new to Ionic.
I want to use ionic push notification for android phone.
I followed all the instruction from ionic website
For the debugging, I typed ionic serve
And I saw
"Uncaught ReferenceError: PushNotification is not defined"
in Chrome console.
Of course, notification is not working.
What am I missing ?
Any comment would be very helpful.Thank you.
Below is What I have done
I have put below code in terminal
ionic add ionic-platform-web-client
ionic plugin add phonegap-plugin-push
ionic io init
My ionic config info
dev_push is false,
There is 'app_id'
There is 'api_key'
There is 'gcm_key'
NodeJS
v5.2.0 (I tried also v4.2.2)
Ionic cli
v1.7.12
Below code is in $ionicPlatform.ready
var io = Ionic.io();
var user = Ionic.User.current();
if (!user.id) {
user.id = Ionic.User.anonymousId();
};
// Just add some dummy data..
user.set('name', 'moka');
user.set('bio', 'This is my little bio');
user.save();
var push = new Ionic.Push({
"onNotification": function(notification) {
alert('Received push notification!');
},
"pluginConfig": {
"android": {
"iconColor": "#0000FF"
}
}
});
var callback = function(data) {
push.addTokenToUser(user);
user.save();
};
push.register(callback);
// Edit
I changed form
ionic config set dev_push false
to
ionic config set dev_push true
It does not show no longer
"Uncaught ReferenceError: PushNotification is not defined"
However I am not sure if it's correct way.
Because it was written on this tutorial
to turn off your development mode
ionic push --google-api-key your-google-api-key
ionic config set gcm_key your-gcm-project-number
ionic config set dev_push false
So it does not matter "Uncaught ReferenceError: PushNotification is not defined", if I want to test on real android device ?
No it does not matter.
In fact as you have mentioned dev_push must be false while testing it out in real devices.
You can either set it false manually ionic config set dev_push false or not mention it anywhere(by default it is false) :)
Cordova & Phonegap plugins only work on emulators and devices. They will not work on any broswers.
Although with Ionic you can mute those errors a good practice could be to wrap your code like this:
if (typeof PushNotification === "defined") {
// your code here
}
This way it wont throw any errors when you write BDD or E2E tests.
You can also add your code inside the:
document.addEventListener("deviceready", function () {
}
I was able to fix this error following:
ionic remove ionic-platform-web-client
cordova plugin remove phonegap-plugin-push
ionic add ionic-platform-web-client
ionic plugin add phonegap-plugin-push
ionic io init
Related
I'm using this code:
this.watchID = navigator.geolocation.watchPosition((localizacion) => {
console.log("En el enviarPos", localizacion);
}, (err) => {
console.log(err);
}, { enableHighAccuracy: true });
It works in background, but only doesn't work when the phone is locked.
Error:
GeolocationPositionError {code: 3, message: "Timeout expired"}
I was facing same issue but I switched to Geocoder, and it's working fine for me, also it gives lot of info,
=> For Ionic 3
ionic cordova plugin add cordova-plugin-nativegeocoder
npm install --save #ionic-native/native-geocoder#4
=> For Ionic 4
ionic cordova plugin add cordova-plugin-nativegeocoder
npm install --save #ionic-native/native-geocoder
I am trying to add AppRate to my app based on the
https://ionicframework.com/docs/v3/native/app-rate/
example
TypeError: AppRate.preferences.openUrl is not a function. (In
'AppRate.preferences.openUrl(iOSStoreUrl)', 'AppRate.preferences.openUrl' is undefined)
That method is indeed missing on the object when inspected in debugger.
On the plugin documentation they add the method manually.
https://github.com/pushandplay/cordova-plugin-apprate
This approach fails for me however, too. My ionic app has no window object.
I had the same issue, but in ionic 4.
I solved it, firstly, reinstall the plugin from git repository or cordova plugins registry (to make sure we have the function openUrl added) and adding the missing method to #ionic-native/app-rate/ngx/index.d.ts like :
export interface AppRatePreferences {
...
...
...
openUrl?:(url:string) => void;
}
And after where you have used the call of the plugin, you add openUrl: appRate.preferences.openUrl to preferences properties like :
appRate.preferences = {
displayAppName: '',
storeAppURL: {
ios: '<my_app_id>',
android: 'market://details?id=<package_name>',
windows: 'ms-windows-store://pdp/?ProductId=<the apps Store ID>',
blackberry: 'appworld://content/[App Id]/'
},
openUrl: appRate.preferences.openUrl
};
Hope it helps you.
For ionic 3, Make sure the latest versions are installed with support for #ionic-native/app-rate#4
In my case I have solved it by installing version 4 of #ionic-native and version 1.4.0 of apprate.
Try this:
$ ionic cordova plugin rm cordova-plugin-apprate
$ ionic cordova plugin add cordova-plugin-apprate#1.4.0 --save --exact
$ npm install --save #ionic-native/app-rate#4
I have an Ionic 3 app that requires to use Media Plugin.
When I press the "record" button on my app, this code block is executed:
this.platform.ready().then(() => {
this.fileName = this.commentsProvider.getFileName(this.platform);
this.filePath = this.commentsProvider.getFilePath(this.platform, this.fileName);
this.audio = this.media.create(this.filePath);
this.audio.startRecord();
this.recording = true;
});
And it doesn't works. The console throws:
console.warn: Native: tried accessing the Media plugin but it's not installed.
NOTE: I'm runing the app in a connected Android device, via USB.
You can see I'm using platform.ready() and anyway I still have this problem.
Any idea?
Thank's in advance!
EDIT: I've already deleted node_modules and plugins folders, and ran npm install, and the problem persists.
I am using one signal plugin for push notification.
First i installed the one signal plugin.
ionic cordova plugin add onesignal-cordova-plugin
npm install --save #ionic-native/onesignal
Here is my code
this.platform.ready().then(() => {
this.oneSignal.getIds().then((ids)=>{
console.log("USER ID");
console.log(ids.userId);
}).catch((e)=>{
console.log("error")
console.log(e);
})
})
But does not get app id.why?
The error is plugin_not_installed.
I remove this plugin again added.
But still get the same error. and also getting this type of err.
Ionic Native: deviceready did not fire within 5000ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.
Native: deviceready did not fire within 5000ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.
Kindly advice me,
Thanks.
I updated my Xcode today and run my Ionic app on iOs9 build. New error pop up on Xcode console each time I click from a ng-repeat list to a detail view. Error is:
error JSON.stringify()ing argument: TypeError: JSON.stringify cannot serialize cyclic structures.
The error seem to be caused by AngularFire firebaseObject. Here is how to duplicated the problem (has to build to ios and see the error in xcode7):
Use Ionic starter sidemenu template by running:
$ sudo npm install -g ionic cordova
$ ionic start myApp sidemenu
modify the PlaylistsCtrl and PlaylistCtrl as below:
.controller('PlaylistsCtrl', function($scope, $firebaseObject, $firebaseArray) {
$scope.playlists = [];
var ref = new Firebase(MYFIREBASEURL);
var tasks = $firebaseArray(ref.child('tasks'));
$scope.playlists = tasks;
})
.controller('PlaylistCtrl', function($scope, $stateParams, $firebaseObject) {
var id = $stateParams.playlistId;
console.log(id);
var ref = new Firebase(MYFIREBASEURL);
var task = $firebaseObject(ref.child('tasks').child(id));
console.log(task);
$scope.task = task;
});
Modify the 2 views: Playlists and Playlist that come with the starter template as below:
<ion-view view-title="Playlists">
<ion-content>
<ion-list>
<ion-item ng-repeat="playlist in playlists" href="#/app/playlists/{{playlist.$id}}">
{{playlist.$id}} / {{playlist.title}}
</ion-item>
<ion-item class="item-text-wrap">{{task.title}} / {{task.$id}}</ion-item>
</ion-list>
</ion-content>
</ion-view>
<ion-view view-title="Playlist">
<ion-content>
<h1>{{task.$id}}</h1>
<p>{{task.title}}</p>
</ion-content>
</ion-view>
Build the sidemenu starter app by running $ionic build ios and then open the xcode file in xcode7. Run on ACTUAL DEVICE - like an iPhone 5S (my device). Take note in the xcode log window.
When click the list item and go to the detail playlist view, it throw error like this
2015-09-29 10:20:03.868 firebaseObjerr[572:142668] error JSON.stringify()ing argument: TypeError: JSON.stringify cannot serialize cyclic structures.
And adding the ios9 fix indicated here: enter link description here
did not solve the problem.
Please help!
[EDIT]
Here is my system info (As Ionic, Cordova are latest):
Your system information:
Cordova CLI: 5.3.3
Gulp version: CLI version 3.9.0
Gulp local:
Ionic Version: 1.1.0
Ionic CLI Version: 1.6.4
Ionic App Lib Version: 0.3.8
ios-deploy version: 1.7.0
ios-sim version: 5.0.1
OS: Mac OS X Yosemite
Node Version: v0.12.5
Xcode version: Xcode 7.0 Build version 7A220
And for firebase and AngularFire, I grab it from firebase CDN:
<!-- Firebase -->
<script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
<!-- AngularFire -->
<script src="https://cdn.firebase.com/libs/angularfire/1.1.2/angularfire.min.js"></script>
I had a similar problem. It turns out it was being caused in the following scenario:
var userRef = new Firebase(FIREBASE_URL + '/users').child(uid);
profile = $firebaseObject(userRef);
console.log(profile)
Is it possible you are trying to log a firebase data structure that has a cyclic dependency?
Try removing your console.log() lines.
Removing console.log worked for me. I had to do the following to my code (Ionic Google Analytics plugin - https://ionicframework.com/docs/native/google-analytics/)
// Google Analytics (console.log throws errors)
return GoogleAnalytics.startTrackerWithId("UA-97459358-1")
.then(() => {
//console.log('Google analytics is ready now');
return GoogleAnalytics.enableUncaughtExceptionReporting(true)
}).then((_success) => {
//console.log("startTrackerWithId success")
}).catch((_error) => {
//console.log("enableUncaughtExceptionReporting", _error)
})