phonegap / phonegap-plugin-push

Register and receive push notifications
MIT License
1.94k stars 1.91k forks source link

iOS Notification via GCM #115

Closed tomercagan closed 8 years ago

tomercagan commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

+1

bau720123 commented 8 years ago

+1

Mirodil commented 8 years ago

+1

sombriks commented 8 years ago

+1

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

ghost commented 8 years ago

How???

Clearly the plugin README.md says:

Supported Platforms

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

if not please add that asap! +1

trojanc commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

Is there an ETA for this enhancement?

macdonst commented 8 years ago

@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 commented 8 years ago

@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 commented 8 years ago

@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 commented 8 years ago

@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:

Hope that information help someone too.

Regards,

macdonst commented 8 years ago

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

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

ghost commented 8 years ago

@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 ;)

deluxeuo commented 8 years ago

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 commented 8 years ago

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:

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 commented 8 years ago

Bruno .. this is a problem in with PushPlugin?

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

ghost commented 8 years ago

@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 commented 8 years ago

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 commented 8 years ago

@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 commented 8 years ago

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: https://github.com/phonegap/phonegap-plugin-push/compare/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 commented 8 years ago

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

rolivav commented 8 years ago

+1!

drlebedev commented 8 years ago

+1

behaghel commented 8 years ago

@jtbdevelopment I have given it a spin. The register fails with this error:

2015-11-11 23:48:25.914 Hozana[2426:1879459] Push Plugin register called
2015-11-11 23:48:25.915 Hozana[2426:1879459] Using GCM Notification
2015-11-11 23:48:25.915 Hozana[2426:1879459] Using GCM Sandbox
2015-11-11 23:48:25.938 Hozana[2426:1879459] Push Plugin register success: <51d404ef 9cXXXb68 4bd8d43e 37f830d9 bd7c9b83 56270d84 4217e393 dca74d49>
2015-11-11 23:48:26.098 Hozana[2426:1879459] Push Plugin register success: <51d404ef 9cXXXb68 4bd8d43e 37f830d9 bd7c9b83 56270d84 4217e393 dca74d49>
2015-11-11 23:48:26.528: GGLInstanceID | Invalid last checkin timestamp in future.
2015-11-11 23:48:26.538 Hozana[2426:1879459] Registration to GCM failed with error: The operation couldn’t be completed. (com.google.iid error 6.)
2015-11-11 23:48:26.542 Hozana[2426:1879459] ["gcm_error"]
2015-11-11 23:48:26.543 Hozana[2426:1879459] Notification Error : Error:  - The operation couldn’t be completed. (com.google.iid error 6.)
2015-11-11 23:48:26.560: GGLInstanceID | Invalid last checkin timestamp in future.
2015-11-11 23:48:26.584: GGLInstanceID | Unable to find token in cache Error Domain=com.google.iid Code=-25300 "(null)"

Let me know if you'd want an issue on your repo.

jtbdevelopment commented 8 years ago

On 11/11/2015 6:53 PM, Hubert Behaghel wrote:

@jtbdevelopment https://github.com/jtbdevelopment I have given it a spin. The register fails with this error:

|2015-11-11 23:48:25.914 Hozana[2426:1879459] Push Plugin register called 2015-11-11 23:48:25.915 Hozana[2426:1879459] Using GCM Notification 2015-11-11 23:48:25.915 Hozana[2426:1879459] Using GCM Sandbox 2015-11-11 23:48:25.938 Hozana[2426:1879459] Push Plugin register success: <51d404ef 9cXXXb68 4bd8d43e 37f830d9 bd7c9b83 56270d84 4217e393 dca74d49> 2015-11-11 23:48:26.098 Hozana[2426:1879459] Push Plugin register success: <51d404ef 9cXXXb68 4bd8d43e 37f830d9 bd7c9b83 56270d84 4217e393 dca74d49> 2015-11-11 23:48:26.528: GGLInstanceID | Invalid last checkin timestamp in future. 2015-11-11 23:48:26.538 Hozana[2426:1879459] Registration to GCM failed with error: The operation couldn’t be completed. (com.google.iid error 6.) 2015-11-11 23:48:26.542 Hozana[2426:1879459] ["gcm_error"] 2015-11-11 23:48:26.543 Hozana[2426:1879459] Notification Error : Error: - The operation couldn’t be completed. (com.google.iid error 6.) 2015-11-11 23:48:26.560: GGLInstanceID | Invalid last checkin timestamp in future. 2015-11-11 23:48:26.584: GGLInstanceID | Unable to find token in cache Error Domain=com.google.iid Code=-25300 "(null)" |

Let me know if you'd want an issue on your repo.

— Reply to this email directly or view it on GitHub https://github.com/phonegap/phonegap-plugin-push/issues/115#issuecomment-155947975.

Are you using a registered project # from google cloud with GCM permissioning? The only time I got 6 was early on when I wasn't registering a valid id. Otherwise you'd need to provide some sort of working example.

behaghel commented 8 years ago

I'm using the same senderID that I use for the pure GCM android-only side of things. And on Android it's been working fine. Am I missing something? Otherwise I'll try and provide a minimal example to reproduce it on your end. On Thu, 12 Nov 2015 at 04:26, JTB Development notifications@github.com wrote:

On 11/11/2015 6:53 PM, Hubert Behaghel wrote:

@jtbdevelopment https://github.com/jtbdevelopment I have given it a spin. The register fails with this error:

|2015-11-11 23:48:25.914 Hozana[2426:1879459] Push Plugin register called 2015-11-11 23:48:25.915 Hozana[2426:1879459] Using GCM Notification 2015-11-11 23:48:25.915 Hozana[2426:1879459] Using GCM Sandbox 2015-11-11 23:48:25.938 Hozana[2426:1879459] Push Plugin register success: <51d404ef 9cXXXb68 4bd8d43e 37f830d9 bd7c9b83 56270d84 4217e393 dca74d49> 2015-11-11 23:48:26.098 Hozana[2426:1879459] Push Plugin register success: <51d404ef 9cXXXb68 4bd8d43e 37f830d9 bd7c9b83 56270d84 4217e393 dca74d49> 2015-11-11 23:48:26.528: GGLInstanceID | Invalid last checkin timestamp in future. 2015-11-11 23:48:26.538 Hozana[2426:1879459] Registration to GCM failed with error: The operation couldn’t be completed. (com.google.iid error 6.) 2015-11-11 23:48:26.542 Hozana[2426:1879459] ["gcm_error"] 2015-11-11 23:48:26.543 Hozana[2426:1879459] Notification Error : Error: - The operation couldn’t be completed. (com.google.iid error 6.) 2015-11-11 23:48:26.560: GGLInstanceID | Invalid last checkin timestamp in future. 2015-11-11 23:48:26.584: GGLInstanceID | Unable to find token in cache Error Domain=com.google.iid Code=-25300 "(null)" |

Let me know if you'd want an issue on your repo.

— Reply to this email directly or view it on GitHub < https://github.com/phonegap/phonegap-plugin-push/issues/115#issuecomment-155947975 .

Are you using a registered project # from google cloud with GCM permissioning? The only time I got 6 was early on when I wasn't registering a valid id. Otherwise you'd need to provide some sort of working example.

— Reply to this email directly or view it on GitHub https://github.com/phonegap/phonegap-plugin-push/issues/115#issuecomment-155994391 .

jtbdevelopment commented 8 years ago

That should work On Nov 12, 2015 3:28 AM, "Hubert Behaghel" notifications@github.com wrote:

I'm using the same senderID that I use for the pure GCM android-only side of things. And on Android it's been working fine. Am I missing something? Otherwise I'll try and provide a minimal example to reproduce it on your end. On Thu, 12 Nov 2015 at 04:26, JTB Development notifications@github.com wrote:

On 11/11/2015 6:53 PM, Hubert Behaghel wrote:

@jtbdevelopment https://github.com/jtbdevelopment I have given it a spin. The register fails with this error:

|2015-11-11 23:48:25.914 Hozana[2426:1879459] Push Plugin register called 2015-11-11 23:48:25.915 Hozana[2426:1879459] Using GCM Notification 2015-11-11 23:48:25.915 Hozana[2426:1879459] Using GCM Sandbox 2015-11-11 23:48:25.938 Hozana[2426:1879459] Push Plugin register success: <51d404ef 9cXXXb68 4bd8d43e 37f830d9 bd7c9b83 56270d84 4217e393 dca74d49> 2015-11-11 23:48:26.098 Hozana[2426:1879459] Push Plugin register success: <51d404ef 9cXXXb68 4bd8d43e 37f830d9 bd7c9b83 56270d84 4217e393 dca74d49> 2015-11-11 23:48:26.528: GGLInstanceID | Invalid last checkin timestamp in future. 2015-11-11 23:48:26.538 Hozana[2426:1879459] Registration to GCM failed with error: The operation couldn’t be completed. (com.google.iid error 6.) 2015-11-11 23:48:26.542 Hozana[2426:1879459] ["gcm_error"] 2015-11-11 23:48:26.543 Hozana[2426:1879459] Notification Error : Error: - The operation couldn’t be completed. (com.google.iid error 6.) 2015-11-11 23:48:26.560: GGLInstanceID | Invalid last checkin timestamp in future. 2015-11-11 23:48:26.584: GGLInstanceID | Unable to find token in cache Error Domain=com.google.iid Code=-25300 "(null)" |

Let me know if you'd want an issue on your repo.

— Reply to this email directly or view it on GitHub <

https://github.com/phonegap/phonegap-plugin-push/issues/115#issuecomment-155947975

.

Are you using a registered project # from google cloud with GCM permissioning? The only time I got 6 was early on when I wasn't registering a valid id. Otherwise you'd need to provide some sort of working example.

— Reply to this email directly or view it on GitHub < https://github.com/phonegap/phonegap-plugin-push/issues/115#issuecomment-155994391

.

— Reply to this email directly or view it on GitHub https://github.com/phonegap/phonegap-plugin-push/issues/115#issuecomment-156032625 .

leonardobazico commented 8 years ago

@behaghel, I have the same issue. I did a workaround for that.

When the user opens the app, check if has a registration id, otherwise:

var push = PushNotification.init(options);

Not the best way, but works for me.

alamops commented 8 years ago

Some fix?

macdonst commented 8 years ago

@jtbdevelopment I'm running into the same problem as @behaghel

jtbdevelopment commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

@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 commented 8 years ago

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 commented 8 years ago

@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 commented 8 years ago

Merged in 1.5.x branch.

ahlidap commented 8 years ago

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 commented 8 years ago

Merged into master.

kh411d commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

@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 commented 8 years ago

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

All working good thanks

barocsi commented 8 years ago

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 commented 8 years ago

@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 commented 8 years ago

(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 commented 8 years ago

I have just switched to APNS.

prettyGIT commented 7 years ago

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?