Coder Social home page Coder Social logo

awspushmanager's Introduction

AWSPushManager

AWS SNS Push registration manager

The code of this library was extracted from the mobile hub example application.

It works with both Objective-C and Swift.

Dependencies

Direct dependencies are the AWSCore and AWSSNS frameworks.

To actually be able to communicate with AWS the AWSCognito framework is required as well.

Installation

Using CocoaPods

This is the easiest, because it also installs the required dependencies.

Add AWSPushManager to the Podfile.

pod 'AWSPushManager', '~> 0.0.1'

Manual installation

Copy AWSPushManager.h and AWSPushManager.m to your project, and make sure to add the AWSCore and AWSSNS frameworks.

Initialization

Objective-C

Import the headers:

#import <AWSPushManager/AWSPushManager.h>

And update AppDelegate.m to match with the following:

- (BOOL)didFinishLaunching:(UIApplication *)application
              withOptions:(NSDictionary *)launchOptions {

    NSString *platformARN = @"arn:aws:sns:us-east-1:123456789:app/APNS_SANDBOX/SomeAppName";
    [AWSPushManager defaultPushManager].defaultPlatformARN = platformARN;

    return [[AWSPushManager defaultPushManager] interceptApplication:application
                                       didFinishLaunchingWithOptions:launchOptions];
}

- (void)application:(UIApplication *)application
                          didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    [[AWSPushManager defaultPushManager] interceptApplication:application
             didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application
                          didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    [[AWSPushManager defaultPushManager] interceptApplication:application
             didFailToRegisterForRemoteNotificationsWithError:error];
}

- (void)application:(UIApplication *)application
                          didReceiveRemoteNotification:(NSDictionary *)userInfo {
    [[AWSPushManager defaultPushManager] interceptApplication:application
                                 didReceiveRemoteNotification:userInfo];
}

Swift

Import the framework:

import AWSPushManager

Or if not using frameworks import the headers in your App-Bridging-Header.h.

#import <AWSPushManager/AWSPushManager.h>

And update AppDelegate.swift to match with the following:

func application(application: UIApplication,
                didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    let platformARN = "arn:aws:sns:us-east-1:123456789:app/APNS_SANDBOX/SomeAppName"
    AWSPushManager.setDefaultPlatformARN(platformARN)

    return AWSPushManager.defaultPushManager().interceptApplication(application,
                didFinishLaunchingWithOptions: launchOptions)
}

func application(application: UIApplication,
                didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    AWSPushManager.defaultPushManager().interceptApplication(application,
                didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}

func application(application: UIApplication,
                didFailToRegisterForRemoteNotificationsWithError error: NSError) {
    AWSPushManager.defaultPushManager().interceptApplication(application,
                didFailToRegisterForRemoteNotificationsWithError: error)
}

func application(application: UIApplication,
                didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    AWSPushManager.defaultPushManager().interceptApplication(application,
                didReceiveRemoteNotification: userInfo)
}

Usage

Minimal configuration

To start receiving notifications, you have to subscribe to one or more topics.

Objective-C

- (void)viewDidLoad {
    [super viewDidLoad];
    AWSPushManager *pushManager = [AWSPushManager defaultPushManager];
    [pushManager registerForPushNotifications];
    NSString *topicARN = @"arn:aws:sns:us-east-1:123456789:SomeApp_alldevices";
    [pushManager registerTopicARNs:@[topicARN, ]];
}

Swift

override func viewDidLoad() {
    super.viewDidLoad()
    let pushManager = AWSPushManager.defaultPushManager()
    pushManager.registerForPushNotifications()
    let topicARN = "arn:aws:sns:us-east-1:123456789:SomeApp_alldevices"
    pushManager.registerTopicARNs([topicARN])
}

To respond to notifications anywhere in your application, you can use AWSPushManager's delegate:

Objective-C

- (void)pushManager:(AWSPushManager *)pushManager
        didReceivePushNotification:(NSDictionary *)userInfo;

Swift

func pushManager(pushManager: AWSPushManager!,
        didReceivePushNotification userInfo: [NSObject : AnyObject]!)

Documentation

Full library documentation can be found on CocoaDocs: http://cocoadocs.org/docsets/AWSPushManager/

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

awspushmanager's People

Contributors

koenpunt avatar vorti2 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.