azure-sdk-for-ios/AzurePush
Colby Williams 61cab9589f v0.5.0
Update CosmosDB REST API version to 2018-12-31 to support large partition keys
2019-08-19 10:17:55 -04:00
..
AzurePush.xcodeproj v0.5.0 2019-08-19 10:17:55 -04:00
Source v0.5.0 2019-08-19 10:17:55 -04:00
Tests v0.5.0 2019-08-19 10:17:55 -04:00
README.md Update AzurePush README 2018-10-09 00:33:18 +04:00

README.md

AzurePush

Current State: Preview Release

The SDK for Azure Notification Hubs (which can be found here) has been refactored to ensure its API works seamlessly with the other SDKs in AzureMobile and to provide the best possible developer experience; the result is AzurePush.

AzurePush provides push notification functionality through the Azure Notification Hubs.

Configure

Before using AzurePush, you will need to configure it with your Azure notification hub name and connection string using the AzurePush.configure function. We recommend doing this in application(_:didFinishLaunchingWithOptions:).

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    AzurePush.configure(withHubName: "<Notification Hub Name>", andConnectionString: "<Connection String>")
}

Usage

Native Device Registration

To register a device with a notification hub, call AzurePush.registerForRemoteNotifications(withDeviceToken:tags:completion:) in application(_:didRegisterForRemoteNotificationsWithDeviceToken:).

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    AzurePush.registerForRemoteNotifications(withDeviceToken: deviceToken, tags: []) { r in 
        // successful registration = r.resource
    }
}

Template Device Registration

Templates enable a client application to specify the exact format of the notifications it wants to receive.

To register a device using a template, first create a Template object, then call AzurePush.registerForRemoteNotifications(withDeviceToken:usingTemplate:tags:completion).

let template = Registration.Template(
    name: "<template name>"
    body: "<template body in template expression language>"
    expiry: "<expiry>"
)
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    AzurePush.registerForRemoteNotifications(withDeviceToken: deviceToken, usingTemplate: template, tags: []) { r in 
        // successful registration = r.resource
    }
}

Unregistration

To cancel a native registration, use AzurePush.unregisterForRemoteNotifications(completion:).

AzurePush.unregisterForRemoteNotifications { r in 
    // r.result.isSuccess == successfully registered
}

To cancel a template registration, use AzurePush.unregisterForRemoteNotifications(forRegistrationWithTemplateNamed:completion:).

AzurePush.unregisterForRemoteNotifications(forRegistrationWithTemplateNamed: "<template name>") { r in 
    // r.result.isSuccess == successfully registered
}