Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

iOS Notification via GCM #115

Closed
tomercagan opened this issue Sep 8, 2015 · 54 comments
Closed

iOS Notification via GCM #115

tomercagan opened this issue Sep 8, 2015 · 54 comments

Comments

@tomercagan
Copy link

Recently, I found out that GCM support iOS messaging.

From what I recon, you register device with APNS and then submit the token to GCM and in "return" get a GCM token you can use for pushing notifications to iOS devices. If I understand correctly, GCM just pushes your payload to APNS (but I could be wrong here).

From the little I understand of both native iOS development and of Cordova/PG plugins, it seems like a relatively small change to the iOS code (the part of registering Apple token with GCM) could enable a simpler server notification code.

Does this make sense?
Could this indeed be added?
I've seen that the iOS example code (native) uses dependencies from google - is that something that can be used within the plugin code?

I don't have much experience with either iOS or plugin development but if the above is feasible, and someone can "assist" with it I'd be happy to contribute my time for this.

@trojanc
Copy link

trojanc commented Sep 10, 2015

Hi, I'm interested in this feature too, I'm not that a good iOS developer, so I probably won't be of any help coding for it...

@ghost
Copy link

ghost commented Sep 15, 2015

+1

@bau720123
Copy link

+1

1 similar comment
@Mirodil
Copy link

Mirodil commented Sep 21, 2015

+1

@sombriks
Copy link

+1

so there is no way to use gcm to send notifications to ios for now?

@ghost
Copy link

ghost commented Sep 24, 2015

How???

Clearly the plugin README.md says:

Supported Platforms

  • Android
  • iOS
  • Windows Universal

I think this plugin should be work for all platforms mentioned above, isn't?

if not please add that asap! +1

@trojanc
Copy link

trojanc commented Sep 24, 2015

The plugin does work with those platforms. This issue is a request to have iOS specific notifications work with the Google Cloud Messaging which was released recently. You can still push to iOS using the regular services provided by Apple (APNS)...Some of us just prefer to work with Google API's rather than Apple provided API.

@sombriks
Copy link

indeed.

send push using google infrastructure is about ten times easier and straightforward than the apple counterpart (which requires a boring certificate in order to allow my server send messages).

@ghost
Copy link

ghost commented Sep 24, 2015

Is there an ETA for this enhancement?

@macdonst
Copy link
Member

@bruno-serfe Yes, the plugin works for Android, iOS and Windows Universal.

@sombriks using GCM for iOS is not a silver bullet as you will still need to setup the certificate stuff with Apple as IIRC GCM will just fwd to APNS.

@sombriks
Copy link

@macdonst that's sad news to me. so i have no choice but generate those certificates.

risking run out of the theme, i'm considering use node-apn and node-gcm to do the job on server side and follow the certificate instructions as seen there.

any thoughs?

@tomercagan
Copy link
Author

@macdonst My thought (unverified) was that the CGM servers are already "verified" with the APNS so by using GCM you can forego the requirement for a certificate on your server (as you don't communicate directly with APNS). I don't recall any setup in the GCM iOS tutorial (but maybe it assumes something?). Am I completely off?

@sombriks I am using node-gcm for sending push notifications to android. It is quite painless to use as you can see from their example (https://github.com/ToothlessGear/node-gcm/blob/master/examples/notification.js). I have not used the other - as I am too lazy to setup the Apple developer account and the required certificates.

@ghost
Copy link

ghost commented Sep 25, 2015

@macdonst No, you need a certificate to make the push from the server. With GCM you can get the deviceToken to make the push notification but you also need the certificate to:

  • Google Cloud Messaging. (APNS .p12 cert)
  • Make the push notification. (APNS .pem cert)

Hope that information help someone too.

Regards,

@macdonst
Copy link
Member

@bruno-serfe Never said you didn't need those things.

@sombriks +1 to node-gcm and node-apns

@ghost
Copy link

ghost commented Sep 25, 2015

@macdonst I know, just I was added that information in order if anyone need to use GCM, know that the certificate is required, I only clarified your thought ;)

@leonardopaiva leonardopaiva mentioned this issue Sep 28, 2015
@deluxeuo
Copy link

Friends
I'm trying as well.

My experience so far:

Android I already can work smoothly,
So I tried to use to IOS.

After setting up the project in the apple developer to receive notifications. Then it must download the certificate (p12) and upload

https://developers.google.com/mobile/add?platform=ios&cntapi=gcm&cnturl=https:%2F%2Fdevelopers.google.com%2Fcloud-messaging%2Fios%2Fclient&cntlbl=Continue%20Adding%20GCM%20Support&%3Fconfigured%3Dtrue

After uploading the certificate developer and production, it will bind a new key to the SenderID already created (created when used android). After that it will generate a downloadable file called google-service-info.plist.

With this file you add it into the xcode project

"The file contains configuration details, such as keys and identifiers, for the services you just enabled. After downloading this file, move it to the Supporting Files directory in your Xcode project."

Well, then I ran my application, and got the key generated and tried to make a post to gcm sending my key ios and key cases. I now have a Invalid Registration problem. I believe I'm close.

My question is if I have to modify the code Objetive c somewhere.

@ghost
Copy link

ghost commented Sep 28, 2015

Hi @deluxeuo this plugin not work with iOS and GCM yet, I've received the same "invalidRegistration" message and to resolve that, you need to use apple apn service in order to send the notification. If you're using PHP, you can take a look at this: http://libcapn.org/php-apn/

Remember that you need:

  • For Google Cloud Messaging. (APNS .p12 cert)
  • To make the push notification. (APNS .pem cert)

you can convert p12 cert to .pem using the following:
http://stackoverflow.com/questions/15144046/need-help-converting-p12-certificate-into-pem-using-openssl

Hope that helps

Best regards,

@deluxeuo
Copy link

Bruno .. this is a problem in with PushPlugin?

I was looking for some shipping APNs notification using java. You know something?

@ghost
Copy link

ghost commented Sep 28, 2015

@deluxeuo No, that is a feature not implemented yet as I understand.
May be someting like this: https://github.com/notnoop/java-apns/wiki/installation

@jtbdevelopment
Copy link
Contributor

I have a fork of 1.3 release of this that I am working to add optional GCM support to ios
https://github.com/jtbdevelopment/phonegap-plugin-push/tree/gcm

It's still rough and only partial tested - will continue to fix and take feedback before doing a merge request. I hope to complete the first pass of coding/testing this week.

The main issues are if I am packaging up the google apis decently - they do not offer a framework version. Cocoapods only which is a pain as far as I can tell for cordova.

In any case they ideas is if you add an optional senderID to the ios options it will use GCM.

@macdonst
Copy link
Member

@jtbdevelopment that's awesome, I look forward to the pull request.

Yes, the lack of cocoapod support for Cordova is a pain but were working on it.

@jtbdevelopment
Copy link
Contributor

OK - I was able to prove it out - using GCM I published to an ipad app some simple messages. If others want to give it a whirl - go ahead and try my fork out (remember it's branch gcm) and see the updated doc on specifying senderID and sandbox flag.

Before I bother with a pull request if you can take look at this diff:
master...jtbdevelopment:gcm

As I mentioned, the changes to PushPlugin weren't overly extensive, it's including all the headers/libs from google that's the pain. This winds up dumping a lot of stuff in your plugin. I'm an experienced developer, but have limited Objective-C (wrote 1 fairly complex app a few years ago) and Cordova (working on my first app), so I'm open to better ways of doing things.

Additionally, I opted to keep the entire google pack in there even though I know I could prune at least a few libs (Address Book stuff at least) as I thought it might be easier to include it all for the next time there is a GCM lib upgrade and the next guy doesn't have to hunt and peck to see what's needed. Open to trying to prune it down too.

@telemakhos
Copy link

+1 for this. Hopefully it will be merged soon...

@rolivav
Copy link

rolivav commented Nov 10, 2015

+1!

@drlebedev
Copy link

+1

@jtbdevelopment
Copy link
Contributor

unfortunately, I've not had the issue except as noted when I was registering a bad id. I again went through the process of running in debug mode on an ipad2, breakpointing registration, handler and message handler - everything registers fine. I then sent a gcm content message via curl to gcm and the ipad received it

EDIT 10pm EST: I'll ask dumb question that sender id is defined as string in ios options structure?

@jtbdevelopment
Copy link
Contributor

One thing may be how quickly you are registering - my own app has a fair bit of facebook/server handshaking that happens before push is registered so cordova and google should be good and primed.

For reference this is the app I built. I'm providing the facebook link which has the app store/google play links. Unfortunately, the version that has working notifications is in apple review as I stupidly forget to go set up my prod credentials the first time around. Hopefully less than a week.

https://apps.facebook.com/twistedbattleship/?fb_source=bookmark&ref=bookmarks&count=0&fb_bmpos=_0

Here's the code that registers push
https://github.com/jtbdevelopment/core-games-ionic-ui/blob/master/src/core-games-ionic-ui/services/pushNotifications.js

Here's the full app (note it uses core libraries under my id)
https://github.com/jtbdevelopment/TwistedBattleship

@macdonst
Copy link
Member

macdonst commented Dec 8, 2015

@jtbdevelopment nope, the problem was I can be an idiot. I forgot to upload my .p12 file to GCM. I'm successfully registered now but haven't been able to receive a push but that's probably something dumb I've done.

@jtbdevelopment
Copy link
Contributor

you still need to define all the fields or somebody drops it (presumably apple)
heres a dopey one I've been using

curl --header "Authorization: key=YOURGOOGLEACCESSKEYHERE" --header "Content-Type: application/json" https://android.googleapis.com/gcm/send -d"{"registration_ids":["YOURLONGLONGGCMREGISTRATIONTOKENHERE"], "collapse_key": "Turn", "content_available": true, "notification": { "title": "title", "body": "body", "badge": "1" }}"

@macdonst
Copy link
Member

macdonst commented Dec 8, 2015

@jtbdevelopment Yup, that works. Doesn't seem like you can omit the "notification" part. I was sending raw "data" messages. I'm going to merge your PR in the 1.5.x branch. Thanks for the submission.

@macdonst
Copy link
Member

macdonst commented Dec 8, 2015

Merged in 1.5.x branch.

@ahlidap
Copy link

ahlidap commented Dec 10, 2015

Is it possible to try this out with as a beta version in Phonegap Build?
I have the same app for iOS and Android, and I'm moving to cli-5.2. This would be great as I have everything implement in my side for sending via GCM (no third party service).

thanks in advance

@macdonst
Copy link
Member

Merged into master.

@kh411d
Copy link

kh411d commented Jan 6, 2016

Hi guys, I've been using the 1.5.2 branch, and I still having issue with "Push Plugin register failed", I did successfully add the p12 both dev and prod key to GCM and I'm using the same GCM senderID both for android app and ios, is there any step maybe I accidentaly skipped?

nb: I'm running on ios emulator

2016-01-06 15:49:24.962 xxx[xxx:xxxxxx] Push Plugin register called
2016-01-06 15:49:24.962 xxx[xxx:xxxxxx] PushPlugin.register: setting badge to false
2016-01-06 15:49:24.962 xxx[xxx:xxxxxx] PushPlugin.register: clear badge is set to 0
2016-01-06 15:49:24.963 xxx[xxx:xxxxxx] PushPlugin.register: better button setup
2016-01-06 15:49:24.965 xxx[xxx:xxxxxx] GCM Sender ID xxxxxxxxxxxx
2016-01-06 15:49:24.965 xxx[xxx:xxxxxx] Using GCM Notification
2016-01-06 15:49:24.972 xxx[xxx:xxxxxx] Push Plugin register failed

@alastairmcavoy-S1
Copy link

I think that if you log the details of the error then you'll see that it is due to push not being supported when emulating.

@tyrtok
Copy link

tyrtok commented Jan 20, 2016

using the 1.5.3 branch. facing similar issue with @kh411d but im using it on a ipad.

var push = PushNotification.init({
            android: {
             "senderID": variables.gcmSenderID 
            },
            ios: {
                    alert: "true",
                    badge: "true",
                    sound: "false",
                    senderID: variables.gcmSenderID,
                    gcmSandbox:"true"
            }, 
            windows: {}
        });
Push Plugin register called
GCM Sender ID 1234567890
Push Plugin register failed
using GCM Notification
using GCM Sandbox

is there any configuration needed to be done @ the Apple side?

update: got it fixed by doing the certificate registration between APNS and GCM

@shrijan
Copy link

shrijan commented Jan 29, 2016

@kh411d have you found sol

var push = PushNotification.init({   
            "ios": {"alert": "true", "badge": "true", "sound": "true"}
        });
MosmanEvent[508:118476] Push Plugin register called 
 PushPlugin.register: setting badge to false
 PushPlugin.register: clear badge is set to 0
 PushPlugin.register: better button setup

Any help appreciated

Thanks

@shrijan
Copy link

shrijan commented Jan 29, 2016

Sorry i am stupid i forget to include passphrase in my server stream context.

All working good thanks

@barocsi
Copy link

barocsi commented Feb 24, 2016

I have tested it according to @jtbdevelopment on GCM with Android it works fine.

On iOS, the device gets registered to GCM, receives device token, I send the message, it says success, but the device never receives anything. I have uploaded all certs (dev, prod) to the dev console as well.

What else could I debug?

@Papipo
Copy link

Papipo commented Feb 24, 2016

@barocsi exactly the same happening here. The first time I send notifications, GCM responds with a success response, but further than that it always responds with "NotRegistered".

@shepax
Copy link

shepax commented Mar 1, 2016

(edit you have to see if you are doing the follow)

Logic works as follows

  1. We request device token from apns as usual.
  2. Then we send that token to gcm service with provided api.
  3. Then gcm sends back a another token.
  4. We send that token to app server.
  5. App server can send notifications using that token.

@Papipo
Copy link

Papipo commented Mar 1, 2016

I have just switched to APNS.

@rockdigit
Copy link

Hi, All
I am new to Ionic Push, I appreciate your help

I am failing to register device when the app launches
I totally followed the ionic push guide for the existing project as well as new template project
https://docs.ionic.io/services/push/#plugin-installation
But both case, I got the following log on the Xcode log panel

2016-10-17 03:09:07.119186 myapp[635:162318] Push Plugin register called
2016-10-17 03:09:07.119272 myapp[635:162318] PushPlugin.register: setting badge to false
2016-10-17 03:09:07.119297 myapp[635:162318] PushPlugin.register: clear badge is set to 0
2016-10-17 03:09:07.119312 myapp[635:162318] PushPlugin.register: better button setup
2016-10-17 03:09:07.123228 myapp[635:162318] GCM Sender ID (null)
2016-10-17 03:09:07.123278 myapp[635:162318] Using APNS Notification
2016-10-17 03:09:07.130045 myapp[635:162256] Push Plugin register failed

Ionic Clouding Service configuration and the app configuration is done according to the guide

What do you think about this issue?

@tomercagan
Copy link
Author

I would check the certificates on your server.

Are you in dev/production? Make sure you use the right certificate and the right URL (sandbox or prod).

From: Heart [mailto:[email protected]]
Sent: Monday, October 17, 2016 10:15
To: phonegap/phonegap-plugin-push [email protected]
Cc: tomercagan [email protected]; Author [email protected]
Subject: Re: [phonegap/phonegap-plugin-push] iOS Notification via GCM (#115)

Hi, All
I am new to Ionic Push, I appreciate your help

I am failing to register device when the app launches
I totally followed the ionic push guide for the existing project as well as new template project
https://docs.ionic.io/services/push/#plugin-installation
But both case, I got the following log on the Xcode log panel

2016-10-17 03:09:07.119186 myapp[635:162318] Push Plugin register called
2016-10-17 03:09:07.119272 myapp[635:162318] PushPlugin.register: setting badge to false
2016-10-17 03:09:07.119297 myapp[635:162318] PushPlugin.register: clear badge is set to 0
2016-10-17 03:09:07.119312 myapp[635:162318] PushPlugin.register: better button setup
2016-10-17 03:09:07.123228 myapp[635:162318] GCM Sender ID (null)
2016-10-17 03:09:07.123278 myapp[635:162318] Using APNS Notification
2016-10-17 03:09:07.130045 myapp[635:162256] Push Plugin register failed

Ionic Clouding Service configuration and the app configuration is done according to the guide

What do you think about this issue?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub #115 (comment) , or mute the thread https://github.com/notifications/unsubscribe-auth/AD5axY150BacuIN5eTdZQnKqru52Bm4iks5q0yCJgaJpZM4F5dHQ . https://github.com/notifications/beacon/AD5axdlyUPuPQcD-t32zprFdfwDwXdl1ks5q0yCJgaJpZM4F5dHQ.gif

@bwoodlt
Copy link

bwoodlt commented Nov 22, 2016

I'm having similar issue. Any idea how to debug this?

2016-11-22 16:09:21.323078 SFF[829:242540] Using APNS Notification
2016-11-22 16:09:21.511167 SFF[829:242429] Push Plugin register success: <f091ff5f 0e70e6bf 5a0a4864 5cc3fcb1 96e210e1 1cb9051f 399dde67 b5cf26b9>
2016-11-22 16:09:21.552051 SFF[829:242429] device token f091ff5f0e70e6bf5a0a48645cc9ccb196e210e11cb9051f399dde67b5cf06c2
2016-11-22 16:09:21.579542 SFF[829:242429] active
2016-11-22 16:09:21.579645 SFF[829:242429] PushPlugin skip clear badge
2016-11-22 16:09:48.596097 SFF[829:242429] active
2016-11-22 16:09:48.596185 SFF[829:242429] PushPlugin skip clear badge
2016-11-22 16:09:48.619033 SFF[829:242429] Push Plugin register success: <f091ff5f 0e70y7bf 5a0a4864 5cc3fcb1 96e210e1 1cb9051f 399dde67 b5cf06c2>
2016-11-22 16:09:50.480582 SFF[829:242429] active
2016-11-22 16:09:50.480724 SFF[829:242429] PushPlugin skip clear badge

Thanks in anticipation.

@alastairmcavoy-S1
Copy link

We resorted to using APN and GCM to resolve the problem – we’ve not retried it recently with the newer GCM versions.

Alastair

From: Ifemide [email protected]
Reply-To: phonegap/phonegap-plugin-push [email protected]
Date: Tuesday, 22 November 2016 at 16:15
To: phonegap/phonegap-plugin-push [email protected]
Cc: Alastair McAvoy [email protected], Comment [email protected]
Subject: Re: [phonegap/phonegap-plugin-push] iOS Notification via GCM (#115)

I'm having similar issue. Any idea how to debug this?

2016-11-22 16:09:21.323078 SFF[829:242540] Using APNS Notification
2016-11-22 16:09:21.511167 SFF[829:242429] Push Plugin register success: <f091ff5f 0e70e6bf 5a0a4864 5cc3fcb1 96e210e1 1cb9051f 399dde67 b5cf26b9>
2016-11-22 16:09:21.552051 SFF[829:242429] device token f091ff5f0e70e6bf5a0a48645cc9ccb196e210e11cb9051f399dde67b5cf06c2
2016-11-22 16:09:21.579542 SFF[829:242429] active
2016-11-22 16:09:21.579645 SFF[829:242429] PushPlugin skip clear badge
2016-11-22 16:09:48.596097 SFF[829:242429] active
2016-11-22 16:09:48.596185 SFF[829:242429] PushPlugin skip clear badge
2016-11-22 16:09:48.619033 SFF[829:242429] Push Plugin register success: <f091ff5f 0e70y7bf 5a0a4864 5cc3fcb1 96e210e1 1cb9051f 399dde67 b5cf06c2>
2016-11-22 16:09:50.480582 SFF[829:242429] active
2016-11-22 16:09:50.480724 SFF[829:242429] PushPlugin skip clear badge

Thanks in anticipation.


You are receiving this because you commented.
Reply to this email directly, view it on GitHubhttps://github.com//issues/115#issuecomment-262285663, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACa10dtA-oBMEKPTKAt233JtQGPVdwujks5rAxURgaJpZM4F5dHQ.


This document is private and confidential.
All property, copyright and other rights in it and its contents belong to Newsquest Media Group Limited.
It must not be read, copied, disclosed or otherwise used without Newsquest’s authorisation. Newsquest may exercise its legal rights and remedies in the event of any such unauthorised use.

Newsquest Media Group Limited.

Registered in England, number 01676637. Registered office: Loudwater Mill, Station Road, Loudwater, High Wycombe, Bucks HP10 9TY.

@lock
Copy link

lock bot commented Jun 4, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests