0

I am using PushSharp library. I am able see deviceToken in the sample code https://github.com/Redth/PushSharp

Can anybody help me how to get that ? PushSharp sample code doesn't explain that

 apnsBroker.QueueNotification (new ApnsNotification {
DeviceToken = deviceToken,
Payload = JObject.Parse ("{\"aps\":{\"badge\":7}}")

Same for Android, How can I get the Registration ID's

 foreach (var regId in MY_REGISTRATION_IDS) {
 // Queue a notification to send
gcmBroker.QueueNotification (new GcmNotification {
RegistrationIds = new List<string> { 
    regId
},
Data = JObject.Parse ("{ \"somekey\" : \"somevalue\" }")
});
}

I am sending push notification via my service layer which is developed using webapi. Please suggest.

Vicky
  • 113
  • 9
  • 1
    Hi Vicky. Noticed that this post actually existed before. I added in an answer. Next time, please avoid delete-reposting a question. Give some time for other users to see it and give opportunity for other new questions to be seen. Cheers! :) – AL. Feb 07 '17 at 06:41
  • Thanks AL. Yes. will follow that :) – Vicky Feb 07 '17 at 06:53
  • The device token must be retrieved on the client end, then sent as a POST to your webapi, in order to do this you must use the device's native language or if you're wanting to use Javascript you'll have to use a lib like Cordova http://cordova.apache.org/docs/en/6.x/guide/platforms/android/index.html. – Faraji Anderson Apr 03 '17 at 00:30

1 Answers1

1

The deviceToken (aka Registration Token) is generated on the client app side.

For GCM - Android, to retrieve the registration token, you'll have to call InstanceID.getToken(). See the official documentation -- Setup a GCM Client on Android:

For GCM - iOS, something similar needs to be done (with further settings needed to connect with APNs). See the official documentation -- Setup a GCM Client on iOS. The guide can be adjusted for Objective-C or Swift.

With that said, the code you referred to is under the section labeled APNS Sample Usage, so I guess it's also safe to refer to this post. Or directly from the Apple Developer site if you plan to directly use APNs without GCM.


PS: If you intend to use GCM, I would strongly recommend that you proceed with using the newer version, which is . Official docs here.

Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281
  • Can you please tell me if I can use InstanceID.getToken() in javascript. Do you have any examples. I am using a Hybrid Cordova app. – Vicky Feb 07 '17 at 06:41
  • @Vicky Nope. That was for Android. GCM does not have any support for Javascript, but the newer version (FCM) does. See the docs [here](https://firebase.google.com/docs/cloud-messaging/js/client#access_the_registration_token). Cheers! :) – AL. Feb 07 '17 at 06:43
  • Thanks AL. Is it possible to implement FirebaseInstanceIdService in webapi. – Vicky Feb 07 '17 at 06:44
  • @Vicky I'm not fully familiar with WebAPIs. I suggest looking around the FCM docs for more details. :) – AL. Feb 07 '17 at 06:54