Giter Site home page Giter Site logo

acapulco's Introduction

Acapulco is a Swift library to register and manage push notifications.

Features

  • Ask for permissions to receive push notifications.
  • Register to receive push notifications.
  • Text, badges and sounds.
  • Silent notifications.
  • Send received receipt.
  • Send red receipt.
  • Support for optional parameters inside the notification payload.
  • Open Web page when receiving url parameter.
  • Debug notification payload.

Requirements

  • iOS 8.0+
  • Swift 1.2
  • Xcode 6.3

Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Sample Project

In order to jump start, you can create the certificates in the iOS Development Portal and use the provided sample project to test the notification system. Keep in mind that you need to change the bundle-id of the application, generate the corresponding provisioning profiles and the certificates (distribution and push) as explained in the Local and Remote Notification Programming Guide.

Installation

Manually

You can integrate Alamofire into your project manually, just drag and drop the Acapulco.swift file in your project.

CocoaPods

Cocoapods support is coming, stay tuned.


Usage

Setup remote Push Notification server

In order to maintain the registered device archive and send push notifications you need a remote endpoint. Introducing ThunderBay!

ThunderBay

To speed up the process you can use the sample ThunderBay push notification server and deploy it to your server. However we've setup a demo instance that will be purged frequently, to let you jump start. You can find it at acapulco.dimension.it.

Register for remote notifications

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Attempt to enable push notifications
    let types : UIUserNotificationType = .Badge | .Sound | .Alert
    let settings = UIUserNotificationSettings(forTypes: types, categories: nil)
    UIApplication.sharedApplication().registerUserNotificationSettings(settings)
    return true
}    

Those instructions are intended for iOS 8+.

Setup Acapulco

serverAddress is your endpoint. applicationKey is the application identifier, in this case provided by ThunderBay.

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    Acapulco.sharedInstance.registerAPNSToken(deviceToken, serverAddress:"acapulco.dimension.it", applicationKey: "8ef1bd2601579e98")
}

Handle foreground notifications

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {        
        Acapulco.sharedInstance.didReceiveNotification(userInfo)
        let notification = NotificationFactory.PushReceivedNotification(userInfo)
        NSNotificationCenter.defaultCenter().postNotification(notification) // Post the notification
}

Handle background notifications

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
    Acapulco.sharedInstance.didReceiveNotification(userInfo)
    NSUserDefaults.standardUserDefaults().setObject(userInfo, forKey: "backgroundNotification") // Save the last notification for later user
    let notification = NotificationFactory.PushReceivedNotification(userInfo)
    NSNotificationCenter.defaultCenter().postNotification(notification) // Post the notification
    completionHandler(UIBackgroundFetchResult.NewData)
}

Handle application launches to register again and update the values

We save the last notification received.

func applicationDidBecomeActive(application: UIApplication) {   
    if let backgroundNotification : NSObject = NSUserDefaults.standardUserDefaults().objectForKey("backgroundNotification") as? NSObject {            
        NSUserDefaults.standardUserDefaults().removeObjectForKey("backgroundNotification") // We don't need it anymore
        let notification = NotificationFactory.PushReceivedNotification(backgroundNotification as! [NSObject : AnyObject])
        NSNotificationCenter.defaultCenter().postNotification(notification) // Post the notification
    }
}

Setup callback to get notification type registration result

func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
    application.registerForRemoteNotifications()
}

Creators

Acapulco has been developed with love in Trento, Italy by DIMENSION S.r.l..

Contributors

License

Acapulco is released under the MIT license.

acapulco's People

Contributors

macteo 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.