An API Client for Registering and Unregistering Devices with Urban Airship
Urban Airship is a popular mobile service provider of push notifications, in-app purchases, and Newsstand publications. Although they provide a static library, it includes a lot of things that most people don't need (weighing in at an astounding 12MB), and is not the easiest thing in the world to use.
AFUrbanAirshipClient
is a small, simple client to the Urban Airship API that uses AFNetworking to perform the essential tasks of registering and unregistering devices for push notifications.
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge];
...
}
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
AFUrbanAirshipClient *client = [[AFUrbanAirshipClient alloc] initWithApplicationKey:kUrbanAirshipApplicationKey applicationSecret:kUrbanAirshipApplicationSecret];
[client registerDeviceToken:deviceToken withAlias:nil success:^(id responseObject) {
NSLog(@"Success: %@", responseObject);
} failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
}
If -registerDeviceToken:withAlias:badge:tags:timezone:quietTimeStart:quietTimeEnd:success:failure:
scares you as much as it does me, you'll probably want to stick with -registerDeviceToken:withAlias:success:failure:
, which provides the following default values:
tags
:- Application Bundle Version (e.g. v1.0)
- Operating System (e.g. iOS 6.0)
- Current Locale Identifier (e.g. en_US)
- Device Model (e.g. iPhone)
tz
: The current timezonebadge
:0
quiettime
:nil
If you're the enterprising type, or just happen to have the registration payload ready to go, you can always use
-registerDeviceToken:withPayload:success:failure:
.
Follow AFNetworking on Twitter (@AFNetworking)
AFUrbanAirshipClient is available under the MIT license. See the LICENSE file for more info.