Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add basic push support methods

  • Loading branch information...
commit c65717378315d392a15552bc3084bc0812231dff 1 parent 99d95b9
@theganyo theganyo authored
Showing with 72 additions and 0 deletions.
  1. +15 −0 UGAPI/UGClient.h
  2. +57 −0 UGAPI/UGClient.m
View
15 UGAPI/UGClient.h
@@ -238,6 +238,21 @@ set the response limit in UGQuery as well.
// is also handy for clients, so it is part of the interface.
+(NSString *)getUniqueDeviceID;
+/***************** REMOTE PUSH NOTIFICATIONS *****************/
+
+// call from application:didRegisterForRemoteNotificationsWithDeviceToken: callback
+// will automatically register the passed deviceToken with the usergrid system
+// using the getUniqueDeviceID method to associate this device on the server
+- (UGClientResponse *)setDevicePushToken:(NSData *)newDeviceToken;
+
+// push an "alert" type notification to the remote group, user, or device specified
+// in the path argument. the notifer may be a name or UUID of an apns notifier
+// that has been set up on the usergrid server.
+- (UGClientResponse *)pushAlert:(NSString *)message
+ withSound:(NSString *)sound
+ to:(NSString *)path
+ usingNotifier:(NSString *)notifier;
+
/*********************** ACCESSORS ************************/
// if a user is logged in, this returns the OAuth token for this session.
// UGClient manages this internally, so you never really need it. But if you
View
57 UGAPI/UGClient.m
@@ -1086,6 +1086,63 @@ -(UGClientResponse *)removeSubscriber: (NSString *)queuePath subscriberPath:(NSS
return [self httpTransaction:url op:kUGHTTPDelete opData:nil];
}
+/*************************** REMOTE PUSH NOTIFICATIONS ***************************/
+/*************************** REMOTE PUSH NOTIFICATIONS ***************************/
+/*************************** REMOTE PUSH NOTIFICATIONS ***************************/
+
+- (UGClientResponse *)setDevicePushToken:(NSData *)newDeviceToken
+{
+ // Pull the push token string out of the device token data
+ NSString *tokenString = [[[newDeviceToken description]
+ stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]
+ stringByReplacingOccurrencesOfString:@" " withString:@""];
+
+ // Register device and push token to App Services
+ NSString *deviceId = [UGClient getUniqueDeviceID];
+
+ // create/update device - use deviceId for App Services entity UUID
+ NSMutableDictionary *entity = [[NSMutableDictionary alloc] init];
+ [entity setObject: @"device" forKey: @"type"];
+ [entity setObject: deviceId forKey: @"uuid"];
+ [entity setObject: tokenString forKey: @"apple.notifier.id"];
+
+ UGClientResponse *response = [self updateEntity: deviceId entity: entity];
+
+ if (response.transactionState == kUGClientResponseSuccess) {
+ // connect device to my user
+ response = [self connectEntities: @"users" connectorID: @"me" type: @"devices" connecteeID: deviceId];
+ }
+
+ return response;
+}
+
+- (UGClientResponse *)pushAlert:(NSString *)message
+ withSound:(NSString *)sound
+ to:(NSString *)path
+ usingNotifier:(NSString *)notifier
+{
+ NSDictionary *apsDict = [NSDictionary dictionaryWithObjectsAndKeys:
+ message, @"alert",
+ sound, @"sound",
+ nil];
+
+ NSDictionary *notifierDict = [NSDictionary dictionaryWithObjectsAndKeys:
+ apsDict, @"aps",
+ nil];
+
+ NSDictionary *payloadsDict = [NSDictionary dictionaryWithObjectsAndKeys:
+ notifierDict, notifier,
+ nil];
+
+ NSString *notificationsPath = [path stringByAppendingString: @"/notifications"];
+
+ NSMutableDictionary *entity = [[NSMutableDictionary alloc] init];
+ [entity setObject: notificationsPath forKey: @"type"];
+ [entity setObject: payloadsDict forKey: @"payloads"];
+
+ return [self createEntity: entity];
+}
+
/*************************** SERVER-SIDE STORAGE ***************************/
/*************************** SERVER-SIDE STORAGE ***************************/

0 comments on commit c657173

Please sign in to comment.
Something went wrong with that request. Please try again.