aerogear-ios-push 
This module is beta software, it currently supports Xcode 6.3
iOS Push Notification Registration SDK for the AeroGear UnifiedPush Server
A small and handy library written in Swift 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
Clone this project
Get the dependencies
The project uses OHHTTPStubs framework for stubbing its http network requests and utilizes cocoapods 0.36 release for handling its dependencies. As a pre-requisite, install cocoapods and then install the pod. On the root directory of the project run:
bash
pod install
3. open AeroGearPushSwift.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:
Using Cocoapods
Support for Swift frameworks is supported from CocoaPods-0.36 release upwards. In your Podfile
add:
pod 'AeroGear-Push-Swift'
and then:
pod install
to install your dependencies
Manual Installation
Drag-and-Drop the project
Follow these steps to add the library in your Swift project:
- Add AeroGearPush as a submodule in your project. Open a terminal and navigate to your project directory. Then enter:
bash git submodule add https://github.com/aerogear/aerogear-ios-push.git
- Open the
aerogear-ios-push
folder, and drag theAeroGearPush.xcodeproj
into the file navigator in Xcode. - In Xcode select your application target and under the
Targets
heading section, ensure that the ‘iOS Deployment Target’ matches the application target of AeroGearPush.framework (Currently set to 8.0). - Select the
Build Phases
heading section, expand theTarget Dependencies
group and addAeroGearPush.framework
. - Click on the
+
button at the top left of the panel and selectNew Copy Files Phase
. Rename this new phase toCopy Frameworks
, set theDestination
toFrameworks
, and addAeroGearPush.framework
.
Using a .framework
build
To build the library simply run the build script:
build.sh
The build script will generate a build
folder in the current directory, containing an universal framework library that you can drag-and-drop in your project. The framework build resides in:
build/Release-universal/AeroGearPush.framework
Now, on your application targets’ “General” settings tab and in the “Linked Frameworks and Libraries” section, drag-and-drop the framework build. Then click the 'Build Phases’ tab, click the ’+’ symbol, select New Copy Files Phase
, expand the section, select 'Frameworks’ from the Destination combo box. Click the ’+’ symbol and select the 'AeroGearPush.framework’
You are now ready to use the library in your project.
Example Usage
Push registration
func application(application: UIApplication!, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData!) {
// setup registration
let registration = AGDeviceRegistration(serverURL: NSURL(string: "<# URL of the running AeroGear UnifiedPush Server #>")!)
// attemp to register
registration.registerWithClientInfo({ (clientInfo: AGClientDeviceInformation!) in
// setup configuration
clientInfo.deviceToken = deviceToken
clientInfo.variantID = "<# Variant Id #>"
clientInfo.variantSecret = "<# Variant Secret #>"
// apply the token, to identify THIS device
let currentDevice = UIDevice()
// --optional config--
// set some 'useful' hardware information params
clientInfo.operatingSystem = currentDevice.systemName
clientInfo.osVersion = currentDevice.systemVersion
clientInfo.deviceType = currentDevice.model
},
success: {
println("UnifiedPush Server registration succeeded")
},
failure: {(error: NSError!) in
println("failed to register, error: \(error.description)")
})
}
Push registration using plist config file
In the AppDelegate.swift
file:
“`swift
func application(application: UIApplication!, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData!) {
// setup registration
let registration = AGDeviceRegistration()
// attemp to register
registration.registerWithClientInfo({ (clientInfo: AGClientDeviceInformation!) in
// setup configuration
clientInfo.deviceToken = deviceToken
let currentDevice = UIDevice()
// set some 'useful' hardware information params
clientInfo.operatingSystem = currentDevice.systemName
clientInfo.osVersion = currentDevice.systemVersion
clientInfo.deviceType = currentDevice.model
},
success: {
println("UnifiedPush Server registration succeeded")
},
failure: {(error: NSError!) in
println("failed to register, error: \(error.description)")
})
} ”`
In your application info.plist
, add the following properties:
xml
<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 emtrics are displayed in the AeroGear UnifiedPush Server’s console.
- Send metrics when app is launched due to push notification
swift func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { AGPushAnalytics.sendMetricsWhenAppLaunched(launchOptions) return true }
- Send metrics when the app is brought from background to foreground due to a push notification
swift func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject: AnyObject]) { AGPushAnalytics.sendMetricsWhenAppAwoken(application.applicationState, userInfo: userInfo) }
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.