-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fce8a4
commit 78f3487
Showing
2 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
## Push Notification App Setup | ||
|
||
### VoIP Push - App Setup | ||
|
||
The following setup is required in your application to receive Telnyx VoIP push notifications: | ||
|
||
#### a. Add Push Notifications capability to your Xcode project | ||
|
||
1. Open the xcode workspace associated with your app. | ||
2. In the Project Navigator (the left-hand menu), select the project icon that represents your mobile app. | ||
3. In the top-left corner of the right-hand pane in Xcode, select your app's target. | ||
4. Press the +Capabilities button. | ||
<p align="center"> | ||
<img width="294" alt="Screen Shot 2021-11-26 at 13 34 12" src="https://user-images.githubusercontent.com/75636882/143610180-04e2a98c-bb08-4f06-b81a-9a3a4231d389.png"> | ||
</p> | ||
|
||
6. Enable Push Notifications | ||
<p align="center"> | ||
<img width="269" alt="Screen Shot 2021-11-26 at 13 35 51" src="https://user-images.githubusercontent.com/75636882/143610372-abab46cc-dd2a-4712-9020-240f9dbaaaf7.png"> | ||
</p> | ||
|
||
#### b. Configure PushKit into your app: | ||
1. Import pushkit | ||
```Swift | ||
import PushKit | ||
``` | ||
2. Initialize PushKit: | ||
```Swift | ||
private var pushRegistry = PKPushRegistry.init(queue: DispatchQueue.main) | ||
... | ||
|
||
func initPushKit() { | ||
pushRegistry.delegate = self | ||
pushRegistry.desiredPushTypes = Set([.voIP]) | ||
} | ||
``` | ||
3. Implement PKPushRegistryDelegate | ||
```Swift | ||
extension AppDelegate: PKPushRegistryDelegate { | ||
|
||
// New push notification token assigned by APNS. | ||
func pushRegistry(_ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, for type: PKPushType) { | ||
if (type == .voIP) { | ||
// This push notification token has to be sent to Telnyx when connecting the Client. | ||
let deviceToken = credentials.token.reduce("", {$0 + String(format: "%02X", $1) }) | ||
UserDefaults.standard.savePushToken(pushToken: deviceToken) | ||
} | ||
} | ||
|
||
func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) { | ||
if (type == .voIP) { | ||
// Delete incoming token in user defaults | ||
let userDefaults = UserDefaults.init() | ||
userDefaults.deletePushToken() | ||
} | ||
} | ||
|
||
/** | ||
This delegate method is available on iOS 11 and above. | ||
*/ | ||
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) { | ||
if (payload.type == .voIP) { | ||
self.handleVoIPPushNotification(payload: payload) | ||
} | ||
|
||
if let version = Float(UIDevice.current.systemVersion), version >= 13.0 { | ||
completion() | ||
} | ||
} | ||
|
||
func handleVoIPPushNotification(payload: PKPushPayload) { | ||
if let metadata = payload.dictionaryPayload["metadata"] as? [String: Any] { | ||
|
||
let callId = metadata["call_id"] as? String | ||
let callerName = (metadata["caller_name"] as? String) ?? "" | ||
let callerNumber = (metadata["caller_number"] as? String) ?? "" | ||
let caller = callerName.isEmpty ? (callerNumber.isEmpty ? "Unknown" : callerNumber) : callerName | ||
|
||
|
||
let uuid = UUID(uuidString: callId) | ||
|
||
// Re-connect the client and process the push notification when is received. | ||
// You will need to use the credentials of the same user that is receiving the call. | ||
let txConfig = TxConfig(sipUser: sipUser, | ||
password: password, | ||
pushDeviceToken: "APNS_PUSH_TOKEN") | ||
|
||
|
||
//Call processVoIPNotification method | ||
|
||
try telnyxClient?.processVoIPNotification(txConfig: txConfig, serverConfiguration: serverConfig,pushMetaData: metadata) | ||
|
||
|
||
|
||
// Report the incoming call to CallKit framework. | ||
let callHandle = CXHandle(type: .generic, value: from) | ||
let callUpdate = CXCallUpdate() | ||
callUpdate.remoteHandle = callHandle | ||
callUpdate.hasVideo = false | ||
|
||
provider.reportNewIncomingCall(with: uuid, update: callUpdate) { error in | ||
if let error = error { | ||
print("AppDelegate:: Failed to report incoming call: \(error.localizedDescription).") | ||
} else { | ||
print("AppDelegate:: Incoming call successfully reported.") | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
4. If everything is correctly set-up when the app runs APNS should assign a Push Token. | ||
5. In order to receive VoIP push notifications. You will need to send your push token when connecting to the Telnyx Client. | ||
|
||
```Swift | ||
|
||
let txConfig = TxConfig(sipUser: sipUser, | ||
password: password, | ||
pushDeviceToken: "DEVICE_APNS_TOKEN", | ||
//You can choose the appropriate verbosity level of the SDK. | ||
logLevel: .all) | ||
|
||
// Or use a JWT Telnyx Token to authenticate | ||
let txConfigToken = TxConfig(token: "MY_JWT_TELNYX_TOKEN", | ||
pushDeviceToken: "DEVICE_APNS_TOKEN", | ||
//You can choose the appropriate verbosity level of the SDK. Logs are disabled by default | ||
logLevel: .all) | ||
``` | ||
|
||
For more information about Pushkit you can check the official [Apple docs](https://developer.apple.com/documentation/pushkit]). | ||
|
||
|
||
__*Important*__: | ||
- You will need to login at least once to send your device token to Telnyx before start getting Push notifications. | ||
- You will need to provide `pushMetaData` to `processVoIPNotification()` to get Push calls to work. | ||
- You will need to implement 'CallKit' to report an incoming call when there’s a VoIP push notification. On iOS 13.0 and later, if you fail to report a call to CallKit, the system will terminate your app. More information on [Apple docs](https://developer.apple.com/documentation/pushkit/pkpushregistrydelegate/2875784-pushregistry) | ||
|
||
## Disable Push Notification | ||
|
||
Push notifications can be disabled for the current user by calling : | ||
``` | ||
telnyxClient.disablePushNotifications() | ||
``` | ||
Note : Signing back in, using same credentials will re-enable push notifications. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
## Push Notification Portal Setup | ||
|
||
The Telnyx iOS Client WebRTC SDK makes use of APNS in order to deliver push notifications. If you would like to receive notifications when receiving calls on your iOS mobile device you will have to configure a VoIP push certificate. | ||
|
||
### Creating a VoIP push certificate | ||
|
||
In order to generate VoIP push certificates you will need: | ||
- An Apple developer account | ||
- App BundleID | ||
- CSR (Certificate Signing Request): Explained on Step #7 | ||
|
||
1. Go to https://developer.apple.com/ and login with your credentials. | ||
2. In the __Overview__ section, select __“Certificates, Identifiers & Profiles”__ | ||
|
||
![ios-people-certs-appstoreconnect](/img/ios-people-certs-appstoreconnect.png) | ||
|
||
3. Press the blue “+” button to add a new Certificate: | ||
![ios-certs-id-profiles](/img/ios-certs-id-profiles.png) | ||
|
||
4. Search for “__VoIP Services Certificate__” and Click “__Continue__”: | ||
![ios-voipservices-cert-desc](/img/ios-voipservices-cert-desc.png) | ||
|
||
5. Select the __BundleID__ of the target application, and click “__Continue__” | ||
![ios-create-voipservices-cert](/img/ios-create-voip-srv.png) | ||
|
||
6. Then, you will be requested to upload a CSR from your Mac. | ||
![ios-create-voipservices-cert](/img/ios-create-voipservices-cert.png) | ||
|
||
7. In order to generate a CSR: | ||
a. Open the KeyChain Access of your mac. | ||
b. Go to Keychain Access >> Certificate Assistance > Request a Certificate from a Certificate Authority. | ||
![ios-export-voipservices-request](/img/ios-request-cert-keychain.png) | ||
|
||
c. Add your email address and select “Save to disk” option, and click “__Continue__” | ||
![ios-cert-information](/img/ios-cert-information.png) | ||
|
||
d. Save the Certificate Signing Request (CSR) into your Mac. | ||
![ios-save-csr](/img/ios-save-csr.png) | ||
|
||
8. Once you have created your CSR, press “Choose File” and select the certSign created on step #7. Click “__Continue__” and you are done. | ||
![ios-create-voipservices-cert](/img/ios-create-voipservices-cert.png) | ||
|
||
9. The new Certificate has been created. Now you need to download it: | ||
![ios-download-cert](/img/ios-download-cert-2.png) | ||
|
||
10. Search for the downloaded file (usually named voip_services.cer) and double click on it to install it on your Mac. And that’s all for now! | ||
|
||
### Obtain your Cert.pem and Key.pem files | ||
|
||
In order to allow the Telnyx VoIP push service to send notifications to your app, you will need to export the VoIP certificate and key: | ||
|
||
1. Open Keychain Access on your Mac (where you have installed the VoIP certificate by following the “__Creating a VoIP push certificate__” instructions). | ||
2. Search for “VoIP services” and verify that you have the certificate installed for the BundleID of your application. | ||
![ios-keychain-access](/img/ios-keychain-access.png) | ||
|
||
3. Open the contextual menu and select “Export”: | ||
![ios-export-voipservices](/img/ios-export-voipservices.jpg) | ||
|
||
4. Save the .p12 file (A password will be requested before saving it): | ||
![ios-save-certificate](/img/ios-save-certificate.jpg) | ||
|
||
5. Once the certificate is created you will need to run the following commands to obtain the __cert.pem__ and __key.pem__ files: | ||
```bash | ||
$ openssl pkcs12 -in PATH_TO_YOUR_P12 -nokeys -out cert.pem -nodes -legacy | ||
$ openssl pkcs12 -in PATH_TO_YOUR_P12 -nocerts -out key.pem -nodes -legacy | ||
$ openssl rsa -in key.pem -out key.pem | ||
``` | ||
|
||
> **Note:** After pasting the above content, Kindly check and remove any new line added | ||
6. Now you can go to your Portal account and configure your PN credential. | ||
|
||
### Setup your iOS VoIP credentials on your Portal | ||
|
||
#### Create an iOS Push Credential: | ||
1. Go to portal.telnyx.com and login. | ||
2. Go to the __API Keys__ section on the left panel. | ||
3. From the top bar go to the __Credentials__ tab and select “__Add__” >> __iOS Credential__ | ||
![ios-api-keys-pn](/img/ios-api-keys-pn.jpg) | ||
|
||
4. Set a credential name (You can use your app bundle ID to easy identify your PN credential) and then copy and paste the contents of your __cert.pem__ and __key.pem__ files into the defined sections (Notice that you need to copy from ---BEGIN ####--- to ---END--- sections including those marks): | ||
![ios-add-pn](/img/ios-add-pn.jpg) | ||
|
||
5. Save the new push credential by pressing the __Add Push Credential__ button. | ||
|
||
#### Assign your iOS Push Credential to a SIP Connection: | ||
1. Go to the __SIP Connections__ section on the left panel. | ||
2. Open the Settings menu of the SIP connection that you want to add a Push Credential or [create a new SIP Connection](/docs/voice/sip-trunking/quickstart). | ||
3. Select the WEBRTC tab. | ||
4. Go to the iOS Section and select the PN credential created on “__Create an iOS Push Credential__” | ||
|
||
![ios-select-pn](/img/ios-push.png) | ||
|
||
That’s done. You can now go to your code and start implementing __PushKit__ and __Callkit__ using the __TelnyxRTC SDK__ and receive VoIP push notifications into your iOS device. |