How to fetch IOS device token using ionic? - ios

Ionic version 2.0
Cordova version 6.3.1
Xcode 8
Have already tried these two links but it did not help.
http://ngcordova.com/docs/plugins/pushNotifications/
https://github.com/hollyschinsky/PushNotificationSample
Looking for a detailed tutorial/material for fetching device token of IOS using ionic.

http://ngcordova.com/docs/plugins/pushNotifications/
Try this only
I also faced the same problem.
Kindly check the IOS OS version of test device. If it is 10.0 or above please do
appropriate changes in Xcode settings in capabilties section
Allow push notification ( it should be checked).
PFB:
Push Notification is not working on iOS 10

you have to use this plugin
if ( device.platform == 'iOS'){
pushNotification.register(
tokenHandler,
errorHandler,
{
"badge":"true",
"sound":"true",
"alert":"true",
"ecb":"onNotificationAPN"
});
}
}
Write this after the device ready event.
function errorHandler(error) {
alert(error);
}
This is the error callback function.
function tokenHandler(result){
// Your iOS push server needs to know the token before it can push to this device
// here is where you might want to send it the token for later use.
//alert('device token = ' + result);
sDeviceId = result ;
}
Here in sDeviceId you can get your device token.

To work with Ionic push notification you must be having recent Ionic version released i.e. Ionic version 2, if you have older version (lower than Ionic version 1) it will not work.
The CordovaPush,CordovaPush v5 are already deprecated so don't use them.
For detailed understanding of push notification in Ionic 2 please refer this ionic 2 push

Related

Push Notification is not working on iOS 10

After the installing the new update of iOS 10, push notifications are not working, while the same implementation of code is working for iOS 9. Is there any new thing for iOS 10 for push notification. As, I am not able figure it out. Also, is it necessary to turn on push notification under capabilities.
Need some changes for iOS 10 with xCode 8 GM You need to implement UserNotification.framework and their delegate methods to get work of push notifications and in capabilities needs to enable Push Notifications.
You have to import new UserNotification.framework. Please follow this link : Push notification issue with iOS 10
Enabling the push notifications capabilities were not required as part of Xcode 7. This is now required in Xcode 8. By enabling push notifications capabilities in Xcode 8, it'll add the following changes:
project.pbxproj
com.apple.Push = {
enabled = 1;
};
*.entitlements (for development)
<key>aps-environment</key>
<string>*development*</string>
*.entitlements (for enterprise and production)
<key>aps-environment</key>
<string>*production*</string>
On iOS 10 is necessary add the Push Notifications entitlement, so if you "Fix Issue" the problem will be resolved automatically.
Problem

Ionic iOS build failing with phonegap-plugin-push

I have added the following package info in my package.json under cordovaPlugins array as the plugin documentation says.
{
"variables": {
"SENDER_ID": "XXXXXXX"
},
"locator": "phonegap-plugin-push"
}
However, the iOS build is failing and I'm unable to figure out what's wrong as I'm new to iOS app development. Here's the partial log that shows the error, which majorly says,
'UIRemoteNotificationType' is deprecated: first deprecated in iOS 8.0 - Use UIUserNotificationType for user notifications and registerForRemoteNotifications for receiving remote notifications instead
and more of similar logs talking about UIRemoteNotificationTypeNone, UIRemoteNotificationTypeBadge etcetera.
Can anyone help me out with this?
I played around a little and updated my ionic and cordova CLI's,
also updated ios-deploy library and re-installed iOS platform. Things are working now.
I think ios-deploy was out dated.

cordova-barcodescanner-plugin Doesn't work in iOS devices

I'm trying to use cordova-barcodescanner-plugin in my ionic project compiled with PhoneGap Build.
https://github.com/hypery2k/cordova-barcodescanner-plugin
When i try to use barcode scanner on iOS devices, my app open barcode correctly but doesn't scan (capture) qrcode.
My config.xml declaration is
gap:plugin name="cordova-plugin-barcodescanner" source="npm"
and my test code is:
cordova.plugins.barcodeScanner.scan(
function (result) {
if(result.cancelled)
return;
alert(result.text);
},
function (error) {
alert("Error scan");
});
Have you notice of the same problem.
Try using the official plugin. It have better support.
https://github.com/phonegap/phonegap-plugin-barcodescanner
I also tried using old version of cli (5.1.1) with 2 plugin:
cordova-barcodescanner-plugin
phonegap-plugin-barcodescanner
**In my PGB app there is
PhoneGap (iOS / Android / Windows)
cli-5.1.1 (3.8.0 / 4.0.2 / 3.8.1)**
Nothing change. When i try to use barcode scanner on iOS device, my app open barcode correctly but doesn't scan (capture) qrcode.
There is an issue opened on Github:
https://github.com/phonegap/phonegap-plugin-barcodescanner/issues/173

Camera.DestinationType.FILE_URI is not working on IOS only

we have migrated a worklight 6.1 application t IBM mobilefirst 7.0 platform and all the functionalities working as expected on the android environment, but in ios we are facing an issue: there is a function called "quick receipt". on click on a button the device camera opens and a photo is taken. The problem is that the photo is not displaying - it returns complete blank page this issue on ios device only but not on Android device.
Camera.DestinationType.FILE_URI is not working on IOS.
for security reason we wont share the code. here is similar prototype code.
html
<div><img alt="QuickReceipts" src="resources/img/camera.png" onclick="imgCapture();"</div>
JavaScript
imgCapture: function (){
navigator.camera.getPicture(this.onSuccess, this.onFail,{quality:80,destinationType:Camera.DestinationType.FILE_URI, targetWidth:600,targetHeight:1050}
},
onSuccess:function(imgData)
{
// applying the css and displaying the img
$("#imgReceipt").attr("src","data:image/jpeg;base64," +imgData);
$("#imgReceipt").css("display", "block");
}
onFail:function(imgData){
// failure msg
}
One suggestion is to attempt to code change as mentioned by Nazmul: http://www.telerik.com/forums/ios-cordova-3-5-0-camera-getpicture-targetwidth-issue.
Another suggestion is to upgrade to the latest 7.1 iFix from IBM Fix Central which contains several Cordova corrections and may address your issue.
If your issue is not resolved still, I suggest to open an IBM PMR (support ticket).

IBM Worklight 6.0 - How to avoid push notifications error when previewing in the iOS Simulator?

I am using IBM Worklight 6.0.0 and testing on iOS 7 Simulator.
I have the following JavaScript error. It appears everytime I login.
Error while trying to retrieve device token from the mobile operating system.
(anonymous function) cordova.js:5312
__log worklight.js:1292
(anonymous function) worklight.js:1377
__updateTokenCallbackError wlgap.ios.js:403
On the client side, my code is:
if (WL.Client.Push){
WL.Client.Push.onReadyToSubscribe = function(){
WL.Logger.debug("onReadyToSubscribe");
if (isPushSubscribed() == false) {
doSubscribe();
}
};
}
if (WL.Client.Push){
WL.Client.Push.registerEventSourceCallback(
"myPush",
"PushAdapter",
"PushEventSource",
pushNotificationReceived);
}
How can I avoid this error?
Use Cordova's device.name API method. You can also use WL.Client.getEnvironment to do the same, but for when previewing in the Worklight Console.
If you get "iPhone Simulator" (or "Preview" in the case Worklight Console), don't enter into those code blocks... do something else instead. Otherwise, continue into them.

Resources