/WCParsePush

Lightweight Push Notifications with Parse.

Primary LanguageObjective-CMIT LicenseMIT

WCParsePush

Lightweight Push Notifications with Parse.com

Description

This small library provides simple interface to the Parse Push Notification Service without the need to include the full Parse iOS SDK. It inlcudes:

  • Device installation registration
  • Channel subscribe/unsubscribe
  • Async and synchoronous save methods
  • Save eventually also after app restart

Installation with CocoaPods

Add the following to your podfile

pod "WCParsePush", "~> 1.1"

Getting started

Add the following to your Application Delegate implementation:

Objective-C:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Setup Push Notifications
    [WCParsePushInstallation setApplicationId:@"<YOUR-APP-ID>" clientKey:@"<YOUR-CLIENT-KEY>"];

    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
    [application registerUserNotificationSettings:settings];
    [application registerForRemoteNotifications];
    
    return YES;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    [[WCParsePushInstallation currentInstallation] setDeviceTokenFromData:deviceToken];
}

Swift:

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

    // Setup Push Notifications
    WCParsePushInstallation.setApplicationId("<YOUR-APP-ID>", clientKey: "<YOUR-CLIENT-KEY>")

	let settings = UIUserNotificationSettings(forTypes: UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, categories: nil)
    application.registerUserNotificationSettings(settings)
    application.registerForRemoteNotifications()
    
    return YES;
}

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {

    let pushInstallation = WCParsePushInstallation.currentInstallation()
    pushInstallation.setDeviceTokenFromData(deviceToken)
}

Swift 2.0:

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

    // Setup Push Notifications
    WCParsePushInstallation.setApplicationId("<YOUR-APP-ID>", clientKey: "<YOUR-CLIENT-KEY>")

	let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
    application.registerUserNotificationSettings(settings)
    application.registerForRemoteNotifications()
    
    return YES;
}

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {

    let pushInstallation = WCParsePushInstallation.currentInstallation()
    pushInstallation.setDeviceTokenFromData(deviceToken)
}

Then to add a channel subscription

Objective-C:

[[WCParsePushInstallation currentInstallation] addChannel:@"Channel"];
[[WCParsePushInstallation currentInstallation] saveEventually];

Swift:

let pushInstallation = WCParsePushInstallation.currentInstallation()
pushInstallation.addChannel("Channel")
pushInstallation.saveEventually()

To reset the badge number

Objective-C:

[[WCParsePushInstallation currentInstallation] setBadge:0];
[[WCParsePushInstallation currentInstallation] saveEventually];

Swift:

let pushInstallation = WCParsePushInstallation.currentInstallation()
pushInstallation.badge = 0
pushInstallation.saveEventually()

Contact

Bas Pellis

License

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