xxxAIRINxxx / ARNPush

Wrap the Apple Push Notification Service (Remote Notification) Code Difference of iOS7 and iOS8.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ARNPush

CI Status Version License Platform

Attention

During the Test....

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [ARNPush setDeviceTokenBlock:^(NSString *deviceToken, NSError *error) {
        if (error) {
            // didFailToRegisterForRemoteNotificationsWithError
        } else {
            // didRegisterForRemoteNotificationsWithDeviceToken
        }
    }];

    [ARNPush setAlertBlock:^(NSDictionary *userInfo) {
        NSLog(@"Call ARNPush Alert Block");
    }];

    [ARNPush setSoundBlock:^(NSDictionary *userInfo) {
        NSLog(@"Call ARNPush Sound Block");
    }];

    [ARNPush setBadgeBlock:^(NSDictionary *userInfo) {
        NSLog(@"Call ARNPush Badge Block");
    }];

    [ARNPush registerForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)
                launchOptions:launchOptions];

    return YES;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    // call ARNPush DeviceTokenBlock
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
    // call ARNPush DeviceTokenBlock
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
   // call ARNPush AlertBlock, SoundBlock, BadgeBlock
}

Requirements

  • iOS 7.0+
  • ARC

Installation

ARNPush is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "ARNPush"

Method Swizzling

replaced the following methods.

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

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo;

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler;

// iOS 8.0+ Only
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler;

License

ARNPush is available under the MIT license. See the LICENSE file for more info.

About

Wrap the Apple Push Notification Service (Remote Notification) Code Difference of iOS7 and iOS8.

License:MIT License


Languages

Language:Objective-C 91.7%Language:Shell 3.8%Language:C 3.1%Language:Ruby 1.4%