AeroGear-Push 1.2.0

AeroGear-Push 1.2.0

TestsTested
LangLanguage Obj-CObjective C
License Apache 2
ReleasedLast Release Oct 2017

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



  • By
  • Red Hat, Inc.

aerogear-ios-push Build Status

iOS Push Notification Registration SDK for the AeroGear UnifiedPush Server

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

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

Building the library

To build the library simply run the build script:

build.sh

The build script will generate a buid folder containing an universal static lib and a framework, sources and documentation are also packaged.

The push-sdk.xcodeproject contains two framework targets pushsdk to build dynamic framework supported from iOS8 and used when runnning unit tests and push-sdk to building static framework supported from iOS7.

NOTE Dynamic framework name should not contain - symbols.

Adding the library to your project

You have different options to add aerogear-push-registration library to your project.

Approach 2: use static lib

  • step 1: copy lib

After you have built the library (see "Building the library" section), from aerogear-ios-push directory, run the copy command:

cp -R build/AeroGearPush-iphoneuniversal/* ../<YourProjectFolder>
  • step 2: header search

Go to root node in the project navigator, and select the target. Select Build Settings, and locate the Header Search Paths setting in the list. Double click on the Header Search Paths item, and a popover will appear. Click the + button, and enter the following:

$SOURCE_ROOT/include
  • step 3: add library

Select the Build Phases tab, and expand the Link Binary With Libraries section and add libpush-sdk-X.X.X.a

  • step 4: add linker flag

Click on the Build Settings tab, and locate the Other linker Flags setting and add -ObjC

NOTE: Please refer to the 64 bits note above.

Approach 3: use framework

  • step 1: copy framework

After you have built the framework (see "Building the library" section), from aerogear-ios-push directory, run the copy command:

cp -R build/AeroGearPush-framework/AeroGearPush.framework ../<YourProjectFolder>
  • step 2: add framework to Build Phases

Go to targets. In Build Phases / Link Binary With Libraries add AeroGearPush.framework

  • step 3: angle bracket your import
#import <AeroGearPush/AeroGearPush.h>

You can use aerogear-push-helloworld as an example of project using aerogear-push-ios-registration as a framework dependency.

NOTE: Please refer to the 64 bits note above.

Example Usage

Push registration

- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

  AGDeviceRegistration *registration = 
    [[AGDeviceRegistration alloc] initWithServerURL:
	   [NSURL URLWithString:@"http://YOUR_SERVER/ag-push/"]];

  [registration registerWithClientInfo:^(id<AGClientDeviceInformation> clientInfo) {

    [clientInfo setDeviceToken:deviceToken];
    [clientInfo setVariantID:@"YOUR IOS VARIANT ID"];
    [clientInfo setVariantSecret:@"YOUR IOS VARIANT SECRET"];

    // --optional config--
    UIDevice *currentDevice = [UIDevice currentDevice];
    [clientInfo setOperatingSystem:[currentDevice systemName]];
    [clientInfo setOsVersion:[currentDevice systemVersion]];
    [clientInfo setDeviceType: [currentDevice model]];
	} success:^() {
      NSLog(@"UnifiedPush Server registration worked");
	} failure:^(NSError *error) {
      NSLog(@"UnifiedPush Server registration Error: %@", error);
  }];
}

Push registration with app plist

In the ppDelegate.m file:

- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

  AGDeviceRegistration *registration = 
    [[AGDeviceRegistration alloc] init];

  [registration registerWithClientInfo:^(id<AGClientDeviceInformation> clientInfo) {

    [clientInfo setDeviceToken:deviceToken];
    UIDevice *currentDevice = [UIDevice currentDevice];
    [clientInfo setOperatingSystem:[currentDevice systemName]];
    [clientInfo setOsVersion:[currentDevice systemVersion]];
    [clientInfo setDeviceType: [currentDevice model]];
  } success:^() {
      NSLog(@"UnifiedPush Server registration worked");
  } failure:^(NSError *error) {
      NSLog(@"UnifiedPush Server registration Error: %@", error);
  }];
}

In your application info.plist, 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.

Receiving Remote Notifications

There are no extra hooks for receiving notifications with the AeroGear library. You can use the existing delegate for receiving remote notifications while the application is running, like:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
  // extract desired value from the dictionary...
}

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
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [AGPushAnalytics sendMetricsWhenAppLaunched:launchOptions];
    return YES;
}
  • Send metrics when the app is brought from background to foreground due to a push notification
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {    
    [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.