Acapulco is a Swift library to register and manage push notifications.
- 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.
- iOS 8.0+
- Swift 1.2
- Xcode 6.3
- 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.
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.
You can integrate Alamofire into your project manually, just drag and drop the Acapulco.swift
file in your project.
Cocoapods support is coming, stay tuned.
In order to maintain the registered device archive and send push notifications you need a remote endpoint. Introducing 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.
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+.
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")
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
Acapulco.sharedInstance.didReceiveNotification(userInfo)
let notification = NotificationFactory.PushReceivedNotification(userInfo)
NSNotificationCenter.defaultCenter().postNotification(notification) // Post the notification
}
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)
}
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
}
}
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
application.registerForRemoteNotifications()
}
Acapulco has been developed with love in Trento, Italy by DIMENSION S.r.l..
Acapulco is released under the MIT license.