Created
July 17, 2014 15:22
-
-
Save Splat/782d6f099311c564965e to your computer and use it in GitHub Desktop.
Cloudmine example of an application using push notifications from a shared application with multiple data stores, IDs and Keys.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AppDelegate.m | |
// CarsGalore | |
// | |
// Copyright (c) 2014 Cloudmine. All rights reserved. | |
// | |
// This is a sample application which shows how to have users and data | |
// in one app but push notifications are coming from a shared app that | |
// is responsible for sending multiple applications notifications. | |
#import "AppDelegate.h" | |
@implementation AppDelegate | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
// Credentials and non-singleton Cloudmine service for the shared push listener | |
NSString *pusherAppIdentifier = @"e63089200d9045fd8c98d7c32fdd81ad"; // Application ID: Pusher-iOS | |
NSString *pusherAppSecret = @"84c8c3f1223b4710b180d181cd6fb1df"; // API Key: Pusher-iOS-Production | |
// Setting the singleton credentials for object and user management specific to this applicatio | |
CMAPICredentials *credentials = [CMAPICredentials sharedInstance]; | |
credentials.appIdentifier = pusherAppIdentifier; // Application ID: CarsGalore | |
credentials.appSecret = pusherAppSecret; | |
CMWebService *pusherWebService = [[CMWebService alloc] initWithAppSecret: pusherAppIdentifier | |
appIdentifier: pusherAppSecret]; | |
CMStore *pusherStore = [[CMStore alloc] init]; | |
// Registered with a nil user for now. Can also register this on the pusherWebService as well. | |
[pusherStore registerForPushNotifications:(UIRemoteNotificationTypeAlert | | |
UIRemoteNotificationTypeBadge | | |
UIRemoteNotificationTypeSound) | |
user: nil | |
callback:^(CMDeviceTokenResult result) { | |
if (result == CMDeviceTokenUploadSuccess || result == CMDeviceTokenUpdated) { | |
NSLog(@"Registered successfully!"); | |
} else { | |
NSLog(@"Uh oh, something happened: %d", result); | |
} | |
}]; | |
// Resetting the singleton credentials for object and user management specific to this application | |
credentials.appIdentifier = @"37acc81f0dcc42bf9d82bffa877e2540"; // Application ID: CarsGalore | |
credentials.appSecret = @"90635c40abfe49eeaaf10f7892f9eba6"; // API Key: CarsGalore-Production | |
CMWebService *carsGaloreWebService = [[CMWebService alloc] init]; // CM service using the app creds (*credentials) | |
CMStore *carsGaloreStore = [[CMStore alloc] init]; // CM storage using the app creds (*credentials) | |
return YES; | |
} | |
// Implement your handlers for the notifications | |
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif { | |
NSString *itemName = [notif.userInfo objectForKey:@"MAGIC"]; // Do something with the message | |
NSLog(itemName); | |
if (app.applicationIconBadgeNumber > 0) { | |
app.applicationIconBadgeNumber = app.applicationIconBadgeNumber -1; | |
} | |
} | |
// Implement your handlers for the notifications | |
- (void)application:(UIApplication *)app didReceiveRemoteNotification:(UILocalNotification *)notif { | |
NSString *itemName = [notif.userInfo objectForKey:@"MAGIC"]; // Do something with the message | |
NSLog(itemName); | |
if (app.applicationIconBadgeNumber > 0) { | |
app.applicationIconBadgeNumber = app.applicationIconBadgeNumber -1; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment