# Using Push Notifications

## Steps to follow for using the push notifications for phone only trip detection

### App needs to create the push notification certificate with Apple app store connect.

The guide for creating the push notification certificate+profile and how to export the certificate as a .p12 file can be found [here](broken://pages/2ZWe6M9xCvfKU5W024bq).

### After successful submission of certificate, system will create a unique device token for the respective device

**Note:** Helpful system apis to verify if the registration of remote push notification is successful or not.

These two functions should be in `AppDelegate.swift` file in order to verify the registration of remote push notifications

```swift
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
    debugPrint("DEVICE TOKEN -> \(deviceTokenString)")
    // pass the device token to the SDK PushNotificationService
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
    // indicates registration failed
}
```

### The device token needs to be passed to SDK using the PushNotificationService to set the token on DriveSync and the device will be registered to receive push notification from DriveSync.

Upon successful registration of device token, the token can be passed to the SDK `PushNotificationService` to set the token on DriveSync.

Please refer to this [page](/drivesync-portal/push-notification.md) for using the service.

### Once the device token is set to DriveSync, the server will be sending silent push notifications to wake up the app in the background and to improve trip detection.

No steps are required on the host app upon receiving silent push notifications except making sure the required permissions are there to facilitate the feature.

### Required permissions

* Allow push notification permission
  * Will be asked during onboarding
* Background app refresh permission
  * Needs to be checked in `info.plist` of the host app


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sdk.ims.tech/readme/ios/using-the-sdk/using-push-notifications.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
