AeroGear-Push-Swift 2.0.1

AeroGear-Push-Swift 2.0.1

TestsTested
LangLanguage SwiftSwift
License Apache 2
ReleasedLast Release Sep 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by corinne krych, Daniel Passos, Julio Cesar, Aiden Keating, Massimiliano Ziccardi.



  • By
  • Red Hat, Inc.

aerogear-ios-push Build Status

This module currently build with Xcode 8 and supports iOS8, iOS9 and iOS 10. For iOS7 support see ObjC version in 1.x_dev branch.

iOS Push Notification Registration SDK for the AeroGear UnifiedPush Server

A small and handy library written in Swift 3.0 that helps to register iOS applications with the AeroGear UnifiedPush Server.

Project Info
License: Apache License, Version 2.0
Build: CocoaPods
Documentation: https://aerogear.org/docs/unifiedpush/aerogear-push-ios/
Issue tracker: https://issues.jboss.org/browse/AGIOS
Mailing lists: aerogear-users (subscribe)
aerogear-dev (subscribe)

Build, test and play with aerogear-ios-push

  1. Clone this project

  2. Get the dependencies

The project uses OHHTTPStubs framework for stubbing its http network requests and utilizes CocoaPods for handling its dependencies. As a pre-requisite, install CocoaPods and then install the pod. On the root directory of the project run:

pod install
  1. open AeroGearPush.xcworkspace

Adding the library to your project

To add the library in your project, you can either use CocoaPods or manual install either by dragging the code or building a framework to install in your project. See the respective sections below for instructions:

In your Podfile add:

pod 'AeroGear-Push-Swift'

and then:

pod install

to install your dependencies.

Finally, inside Xcode, go to the Capabilities section for your target and switch Push Notifications on.

Example Usage

Push registration

  func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
     // setup registration
    let registration = DeviceRegistration(serverURL: URL(string: "<# URL of the running AeroGear UnifiedPush Server #>")!)

    // attemp to register
    registration.register(clientInfo: { (clientDevice: ClientDeviceInformation!) in
        // setup configuration
        clientDevice.deviceToken = deviceToken
        clientDevice.variantID = "<# Variant Id #>"
        clientDevice.variantSecret = "<# Variant Secret #>"

        // apply the token, to identify THIS device
        let currentDevice = UIDevice()

        // --optional config--
        // set some 'useful' hardware information params
        clientDevice.operatingSystem = currentDevice.systemName
        clientDevice.osVersion = currentDevice.systemVersion
        clientDevice.deviceType = currentDevice.model
        },

        success: {
            print("UnifiedPush Server registration succeeded")
        },
        failure: {(error: Error!) in
            print("failed to register, error: \(error.localizedDescription)")
        })
}

Push registration using plist config file

In the AppDelegate.swift file:

  func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
     // setup registration
    let registration = DeviceRegistration(config: "pushconfig")

    // attemp to register
    registration.register(clientInfo: { (clientDevice: ClientDeviceInformation!) in
        // setup configuration
        clientDevice.deviceToken = deviceToken
        let currentDevice = UIDevice()
        // set some 'useful' hardware information params
        clientDevice.operatingSystem = currentDevice.systemName
        clientDevice.osVersion = currentDevice.systemVersion
        clientDevice.deviceType = currentDevice.model
        },       
        success: {
            print("UnifiedPush Server registration succeeded")
        },
        failure: {(error: Error!) in
            print("failed to register, error: \(error.localizedDescription)")
        })
}

In your application, create a new pushconfig.plist file, and add the following properties:

<plist version="1.0">
<dict>
  <key>serverURL</key>
  <string><# URL of the running AeroGear UnifiedPush Server #></string>
  <key>variantID</key>
  <string><# Variant Id #></string>
  <key>variantSecret</key>
  <string><# Variant Secret #></string>
</dict>
</plist>

NOTE: If your UPS server installation uses a self-signed certificate, you can find a quick solution on how to enable support on our troubleshooting page, as well as links for further information on how to properly enable it on your iOS production applications.

Push analytics

If you are interested in monitoring how a push message relates to the usage of your app, you can use metrics. Those metrics are displayed in the AeroGear UnifiedPush Server’s console.

  • Send metrics when app is launched due to push notification
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        PushAnalytics.sendMetricsWhenAppLaunched(launchOptions: launchOptions)
        return true
    }
  • Send metrics when the app is brought from background to foreground due to a push notification
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        // Send metrics when app is launched due to push notification
        PushAnalytics.sendMetricsWhenAppAwoken(applicationState: application.applicationState, userInfo: userInfo)

        // Do stuff ...
        fetchCompletionHandler(UIBackgroundFetchResult.noData)
    }

AeroGear UnifiedPush Server

For more information, checkout our tutorial.

Documentation

For more details about the current release, please consult our documentation.

Development

If you would like to help develop AeroGear you can join our developer’s mailing list, join #aerogear on Freenode, or shout at us on Twitter @aerogears.

Also takes some time and skim the contributor guide

Questions?

Join our user mailing list for any questions or help! We really hope you enjoy app development with AeroGear!

Found a bug?

If you found a bug please create a ticket for us on Jira with some steps to reproduce it.