Native Pushs - What am I missing?

Hi there,

so there’s a deviceToken I get, when developing with Ionic Push and I can recive messages on app run. But what, if I close the app?

I’m regarding to http://docs.ionic.io/docs/push-usage

I get everytime a new deviceToken after calling new Ionic.Push(...).register();, so how could it be to get pushs in the app closed state? I think they’re called native pushs … (?)

I’m still working in developer mode. I think, if I change to production mode then I will get everytime the same deviceToken on registering/running the app.

I really don’t get this whole thing with the tokens, gmc, apns etc. in my head. Can someone PLEASE explain me this whole push thingi with relative simple words?

For example: Who generates the deviceToken, the local device or the ionic push api? Why should I use Ionic User? Do I really need it? … and some more … What is the difference between dev_push and { debug: true }? AppId? Priv/Publ Key? GcmKey? DeviceToken? UserToken? What the … For what are all these keys?

My app is in dev-mode. I allready can recive messages when the app is running. Now my aim is to be able to recive messages for my app when it is NOT running. What I’ll have to do now? I don’t get it.

That’s the problem.

When you switch to production mode the push is sent to the device. The device then displays it if the app is closed, or directly hands it over to the app when the app is open. Then it is handled by the app in the way you defined.

The local device.[quote=“HappyHappyJoyJoy, post:1, topic:38747”]
Why should I use Ionic User? Do I really need it?
[/quote]
You don’t have to and you don’t need it if you persist the device push token yourself.[quote=“HappyHappyJoyJoy, post:1, topic:38747”]
What is the difference between dev_push and { debug: true }?
[/quote]
dev_push = faked push
debug:true = more logging[quote=“HappyHappyJoyJoy, post:1, topic:38747”]
AppId? Priv/Publ Key? GcmKey? DeviceToken? UserToken?
[/quote]
AppID = ID of the app on ionic.io, used as base
Priv/Publ Key = iOS stuff
GcmKey = Android stuff
DeviceToken = Other word for push token
UserToken = no idea[quote=“HappyHappyJoyJoy, post:1, topic:38747”]
My app is in dev-mode. I allready can recive messages when the app is running. Now my aim is to be able to recive messages for my app when it is NOT running. What I’ll have to do now? I don’t get it.
[/quote]Read the docs.

Regarding to http://docs.ionic.io/docs/push-android-setup

Calling https://console.developers.google.com/home/dashboard?project=MyApp I see the projectId and the projectNumber of my registered project (I although have got a google-api-key by registering google push api on that project). So now I have three Ids: The google-api-key, the projectId and the projectNumber.

I used the following console commands:
ionic push --google-api-key google-api-key
ionic config set gcm_key projectNumber

Was this correct? Or should I have set for gcm_key something different than the projectNumber?

Another question: What is senderId? Do I have to set it?

Ionic.Push({
    "pluginConfig": {
        "android": {
            "senderId": ???
        }
    }
});

One more question to the last one.

You don't have to use Ionic User and you don't need it if you persist the device push token yourself.

So let’s say I save that push token on a sqlite-db on device, how do I tell the app at registering to use that old push notification?

If I call the .register()-method of Ionic.Push(…) the event handler gives me every time a new pushToken back … and yes, I left the dev-mode. dev_push is set to false.

… or don’t I have to call the .register()-method each time the app starts???

EDIT: I’m sorry, that was wrong! Everytime I get the SAME deviceToken, even after closing and restarting the app, until I call .unregister().

Okay, I realised that the deviceToken keeps everytime the same, until calling .unregister().

Everytime I call .register I will get the same deviceToken. But if I call .unregister this deviceToken is gone. The next time I call .register() I get a new deviceToken that keeps everytime the same, until calling .unregister().

Although realised: The app can be shut down, but its messaging part keeps running. I still can send a push to the same (registered) deviceToken and it will nativly arrive on the device. A click on the native message starts the app again. Awesome :slight_smile:

But if I start the app the .register-method need to be called!

I hope I could help someone with this.

I quote the docs:
ionic config set gcm_key <your-gcm-project-number>
So yes, this was correct.[quote=“HappyHappyJoyJoy, post:3, topic:38747”]
Another question: What is senderId? Do I have to set it?
[/quote]
No idea. Where did you get that code?[quote=“HappyHappyJoyJoy, post:4, topic:38747”]
So let’s say I save that push token on a sqlite-db on device, how do I tell the app at registering to use that old push notification?
[/quote]
You don’t the device knows its own push token and will always give you the same one. It doesn’t care what you got in a local database, but tells you which one you should save there (and remotely if you want to use it to push to this device).[quote=“HappyHappyJoyJoy, post:4, topic:38747”]
EDIT: I’m sorry, that was wrong! Everytime I get the SAME deviceToken, even after closing and restarting the app, until I call .unregister().
[/quote]Good, that’s what should happen.

Don’t call unregister and you’re fine. You don’t need to do that.

[quote=“HappyHappyJoyJoy, post:5, topic:38747”]
But if I start the app the .register-method need to be called!
[/quote]Exactly.

Wonderfull. I like it this way :wink: