Nexmo / stitch-ios-quickstart

A repository containing everything you need when getting started with the Nexmo Stitch API and the iOS SDKs
MIT License
1 stars 3 forks source link

Finalizing Push notifications #13

Open ericgiannini opened 6 years ago

ericgiannini commented 6 years ago

Thanks, @shams-ahmed! It is a WIP so these are the NeXTSTEPs.

On Wed, Jun 6, 2018 at 2:36 AM, Shams Ahmed notifications@github.com wrote:

@shams-ahmed requested changes on this pull request.

few more changes

In docs/7-push-notifications.md https://github.com/Nexmo/stitch-ios-quickstart/pull/13#discussion_r193334091 :

@@ -0,0 +1,245 @@ +## Sending members Push Notifications with the Nexmo Stitch iOS Conversation SDK + +You have already implemented multiple features with which to stitch together a conversation: initializing an instance of our client, creating a conversation, adding members, displaying conversations' history, or enabling audio. Let's add push notifications now! + +Push Notification depend on Apple Push Notification's service. It is a robust, secure, and highly efficient service for app developers to propagate information throughout a network of interconnected iOS devices, especially those connected together through the Stitch iOS SDK so Push Notifications rely upon APNS entirely. + +In this tutorial we will configure: an APNS certificate in keychain, uploading/downloading an iOS Push Notification certificate, toggling permissions in Xcode. After all of these these prerequisite configurations are in place we will set up the Stitch iOS SDK within the sample app to send our first Push Notification!

send and receive our first push...?

In docs/7-push-notifications.md https://github.com/Nexmo/stitch-ios-quickstart/pull/13#discussion_r193334784 :

+Note: The above command saves the generated JWT to a USER_JWT variable. It also sets the expiry of the JWT to one day from now. + +You can see the JWT for the user by running the following: + +bash +$ echo $USER_JWT + + +### 1.6 The Nexmo Conversation API Dashboard + +If you would like to double check any of the JWT credentials, navigate to your-applications where you can see a table with three entries respectively entitled "Name", "Id", or "Security settings". Under the menu options for "Edit" next to "Delete", you can take a peak at the details of the applications such as "Application name", "Application Id", etc... + + +## 2 - Sending the APNS Certificate to Nexmo, the Vonage API Platform + +The next step is to upload the token generated from step 1.6 to our push service.

this is not correct, JWT token just allows you access to nexmo

In docs/7-push-notifications.md https://github.com/Nexmo/stitch-ios-quickstart/pull/13#discussion_r193335008 :

+### 1.6 The Nexmo Conversation API Dashboard + +If you would like to double check any of the JWT credentials, navigate to your-applications where you can see a table with three entries respectively entitled "Name", "Id", or "Security settings". Under the menu options for "Edit" next to "Delete", you can take a peak at the details of the applications such as "Application name", "Application Id", etc... + + +## 2 - Sending the APNS Certificate to Nexmo, the Vonage API Platform + +The next step is to upload the token generated from step 1.6 to our push service. + +```bash +// Upload +curl -v -X PUT \ +-H "Authorization: Bearer $USER_JWT \ +-H "Content-Type: application/json" \ +-d "{\"token\":\"$hextoken\"}" \ +https://api.nexmo.com/v1/applications/$appid/push_tokens/ios

this happens afterwards

In docs/7-push-notifications.md https://github.com/Nexmo/stitch-ios-quickstart/pull/13#discussion_r193342712 :

+### 1.6 The Nexmo Conversation API Dashboard + +If you would like to double check any of the JWT credentials, navigate to your-applications where you can see a table with three entries respectively entitled "Name", "Id", or "Security settings". Under the menu options for "Edit" next to "Delete", you can take a peak at the details of the applications such as "Application name", "Application Id", etc... + + +## 2 - Sending the APNS Certificate to Nexmo, the Vonage API Platform + +The next step is to upload the token generated from step 1.6 to our push service. + +```bash +// Upload +curl -v -X PUT \ +-H "Authorization: Bearer $USER_JWT \ +-H "Content-Type: application/json" \ +-d "{\"token\":\"$hextoken\"}" \ +https://api.nexmo.com/v1/applications/$appid/push_tokens/ios

// Get Admin JWT token

// Create push token hexdump -ve '1/1 "%.2x"' < applecert.p12 > applecert.pfx.hex hextoken=cat applecert.pfx.hex

// Assign your JWT token jwt_dev=XXXX

// Upload push token curl -v -X PUT -H "Authorization: Bearer $jwt_dev" -H "Content-Type: application/json" -d "{"token":"$hextoken"}" https://api.nexmo.com/v1/applications/$appid/push_tokens/ios

// Retrieve push token for testing curl -H "Authorization: Bearer $jwt_dev" -H "Content-Type: application/json" https://api.nexmo.com/v1/applications/$appid/push_tokens/ios

In docs/7-push-notifications.md https://github.com/Nexmo/stitch-ios-quickstart/pull/13#discussion_r193342929 :

+ +As soon as the Info.plist is configured, we have to register for remote notifications with Apple's method called registerForRemoteNotifications. Since Push Notifications run disrupt an app's User Interface, registration needs to happen on the main thread. To register on the main thread we pass registerForRemoteNotifications as an argument in the async(). method on .main property for DispatchQueue: + +swift +DispatchQueue.main.async(execute: UIApplication.shared.registerForRemoteNotifications) + +### 4.2 Registering Device Token with the SDK + +After the functionality for registering remote notifications is integrated, we program .didRegisterForRemoteNotificationsWithDeviceToken to pass the device token to the SDK: + +```swift +// MARK: +// MARK: Notification + +func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { +client.appLifecycle.push.registeredForRemoteNotifications(with: deviceToken)

indent

In docs/7-push-notifications.md https://github.com/Nexmo/stitch-ios-quickstart/pull/13#discussion_r193343012 :

+// MARK: +// MARK: Notification + +func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { +client.appLifecycle.push.registeredForRemoteNotifications(with: deviceToken) +} + + +## 5 Configuring the Stitch iOS SDK within the iOS App + +The last step is to configure the app to respond to requests for Push Notifications. Drop either of the following lines of code inside of `viewDidLoad(:)` in `ViewController.swift`: + +swift +// listen for push notifications +ConversationClient.instance.appLifecycle.notifications.subscribe(onSuccess: { notification in +// code here

indent

In docs/7-push-notifications.md https://github.com/Nexmo/stitch-ios-quickstart/pull/13#discussion_r193343077 :

+## 5 Configuring the Stitch iOS SDK within the iOS App + +The last step is to configure the app to respond to requests for Push Notifications. Drop either of the following lines of code inside of viewDidLoad(:) in ViewController.swift: + +swift +// listen for push notifications +ConversationClient.instance.appLifecycle.notifications.subscribe(onSuccess: { notification in +// code here +}) + + +You can also subscribe to events for push notifications through the .receiveRemoteNotifications property here: + +``` +ConversationClient.instance.appLifecycle.receiveRemoteNotification.subscribe(onSuccess: { notification in +// code here

indent

In docs/7-push-notifications.md https://github.com/Nexmo/stitch-ios-quickstart/pull/13#discussion_r193351217 :

+ConversationClient.instance.appLifecycle.receiveRemoteNotification.subscribe(onSuccess: { notification in +// code here +}) + + +## 5.1 Configuring `sendBtn` + +In `ViewController.swift` drop in an instance of `ConversationClient` so that we can send messages. + +

  • /// Nexmo Conversation client
  • let client: ConversationClient = {
  • return ConversationClient.instance
  • }() +`` +Next we configure oursendBtnto send messages through ourConversationClient`:

you forgot two major steps requestion push notification permission and app delegate stuff.

request permission https://developer.nexmo.com/sdk/stitch/ios/Classes/PushNotificationController.html#/c:@M@Stitch@objc(cs)NXMPushNotificationController(im)requestPermission

appdelegate method https://developer.nexmo.com/sdk/stitch/ios/Classes/PushNotificationController.html#/s:6Stitch26PushNotificationControllerC014receivedRemoteC0XeXeF

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Nexmo/stitch-ios-quickstart/pull/13#pullrequestreview-126281719, or mute the thread https://github.com/notifications/unsubscribe-auth/AMCHtXpQe_gYV5b7yPxE1iCDcP5Hrp5Qks5t56KrgaJpZM4UZbqS .

ericgiannini commented 6 years ago

Internal guide for navigating push service https://nexmoinc.atlassian.net/wiki/spaces/EN/pages/93061421/Push+Service#PushService-4StepByStepGuide-SendAPNSPushNotification

ericgiannini commented 6 years ago

@shams-ahmed Do you have access to Nexmo / Vonage Apple Developer Program?

ericgiannini commented 6 years ago

@shams-ahmed In the meantime may you review?

ericgiannini commented 6 years ago

@shams-ahmed May you please review the changes? Please feel free to do this tomorrow. No need to do it tonight.