3

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.

Aniruddh
  • 188
  • 5
  • 24

3 Answers3

1

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.

Anuj.T
  • 1,598
  • 16
  • 31
  • the function errorHandler or tokenHandler are not being triggered when i run the code on device – Aniruddh Nov 30 '16 at 09:09
  • In fact the control is not entering inside "pushNotification.register( " itself. – Aniruddh Nov 30 '16 at 09:39
  • Any errors ?? Have you configure your ios certificate properly to receive push notification ? Don't check on simulator, check it on device. – Anuj.T Dec 02 '16 at 04:46
  • I'm not getting any errors in xcode console ... nothing is being processed after pushNotification.register( .... And I have also enabled xcode push notification without any error – Aniruddh Dec 02 '16 at 07:00
1

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

Community
  • 1
  • 1
  • ios version is not 10 or above it's only 8... if I use the same code control will not come inside this at all "document.addEventListener("deviceready", function(){ " t(http://ngcordova.com/docs/plugins/pushNotifications/) so I'm not able to get the device token .....so could you please suggest what can be done.. – Aniruddh Nov 30 '16 at 07:52
  • There is no need to call the register function inside device ready. – Abhishek Srivastava Nov 30 '16 at 08:57
  • There is no need of register a device inside device ready function – Abhishek Srivastava Nov 30 '16 at 08:58
  • you can call register function externall at your will .... preferably in parent controller of your app please try calling once outside the device ready function and let me know the results – Abhishek Srivastava Nov 30 '16 at 08:59
  • then should i add only this $cordovaPush.register(iosConfig).then(function(deviceToken) {// Success -- send deviceToken to server, and store for future useconsole.log("deviceToken: " + deviceToken)$http.post("http://server.co/", {user: "Bob", tokenID: deviceToken})}, function(err) {alert("Registration error: " + err)}); – Aniruddh Nov 30 '16 at 09:03
  • Hmm correct .. get the token and store it for future use – Abhishek Srivastava Nov 30 '16 at 09:23
  • even with that i'm getting these errors 1. Uncaught Error: [$injector:unpr] Unknown provider: $cordovaPushProvider <- $cordovaPush(…) 2.Uncaught ReferenceError: $cordovaPush is not defined(…) ... I have added the plugin cordova plugin add https://github.com/phonegap-build/PushPlugin.git still I'm facing that issue . – Aniruddh Nov 30 '16 at 11:35
  • Please update your push plugin with update command . Sometimes config.xml file does not get updated as per newly installed plugin. – Abhishek Srivastava Dec 01 '16 at 03:48
  • It that doesn't work , remove the push plugin through Cordova command and try readding it. Hope fully it will be resolved. – Abhishek Srivastava Dec 01 '16 at 03:50
0

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

Aniruddh
  • 188
  • 5
  • 24