Skip to content

Commit

Permalink
Updated CMStore register for push notificiation methods for iOS 8
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmick committed Mar 27, 2015
1 parent 0560016 commit 6aa9b97
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
20 changes: 19 additions & 1 deletion ios/ios/src/Storage/CMStore.h
Expand Up @@ -207,6 +207,24 @@ extern NSString * const CMStoreObjectDeletedNotification;
*/
- (void)registerForPushNotifications:(UIRemoteNotificationType)notificationType callback:(CMWebServiceDeviceTokenCallback)callback;

/**
* Registers your application for push notifications. This method will contact Apple, request a token, handle the token
* and register your application with CloudMine. After the token has been sent to Cloudmine, the callback with the result
* will be given.
*
* <strong>Note</strong> - This method will register the stored CMUser to the token. If you do not want to associate the token with the user use
* registerForPushNotifications:user:callback: and pass nil.
*
* @param notificationType The parameter of this method takes a UIRemoteNotificationType bit mask that specifies the initial types of notifications that the application wishes to receive. For example, <tt>(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)</tt>
* @param categories The categories that will be submitted to the call. iOS 8 only (Ignored in lower versions of iOS).
* @param aUser - The user to which this call will be made with.
* @param callback Can be nil - The callback which is called once the Token has been sent to Cloudmine, returns the result of that transaction.
*/
- (void)registerForPushNotifications:(NSInteger)notificationType
categories:(NSArray *)categories
user:(CMUser *)aUser
callback:(CMWebServiceDeviceTokenCallback)callback;

/**
* Registers your application for push notifications. This method will contact Apple, request a token, handle the token
* and register your application with CloudMine. After the token has been sent to Cloudmine, the callback with the result
Expand All @@ -217,7 +235,7 @@ extern NSString * const CMStoreObjectDeletedNotification;
* @param user Can be nil. The user you want to associate the token with.
* @param callback Can be nil - The callback which is called once the Token has been sent to Cloudmine, returns the result of that transaction.
*/
- (void)registerForPushNotifications:(UIRemoteNotificationType)notificationType user:(CMUser *)aUser callback:(CMWebServiceDeviceTokenCallback)callback;
- (void)registerForPushNotifications:(NSInteger)notificationType user:(CMUser *)aUser callback:(CMWebServiceDeviceTokenCallback)callback;

/**
* Unregisters the users token from CloudMine, so they will no longer receive push notifications. Recommended to remove the token when
Expand Down
19 changes: 16 additions & 3 deletions ios/ios/src/Storage/CMStore.m
Expand Up @@ -232,11 +232,16 @@ - (void)registerForPushNotifications:(UIRemoteNotificationType)notificationType
[self registerForPushNotifications:notificationType user:self.user callback:callback];
}

- (void)registerForPushNotifications:(UIRemoteNotificationType)notificationType user:(CMUser *)aUser callback:(CMWebServiceDeviceTokenCallback)callback;
- (void)registerForPushNotifications:(NSInteger)notificationType user:(CMUser *)aUser callback:(CMWebServiceDeviceTokenCallback)callback;
{
[self registerForPushNotifications:notificationType categories:nil user:aUser callback:callback];
}

- (void)registerForPushNotifications:(NSInteger)notificationType categories:(NSArray *)categories user:(CMUser *)aUser callback:(CMWebServiceDeviceTokenCallback)callback;
{
NSAssert([[[UIApplication sharedApplication] delegate] isKindOfClass:[CMAppDelegateBase class]], @"Your Application Delegate MUST Inherit for CMAppDelegateBase in order to register for push notifications in this way!\n \
If you do not want to inherit from CMAppDelegateBase, you will need to use [CMWebService registerForPushNotificationsWithUser:deviceToken:callback:]");

if (!aUser.isLoggedIn) {
NSLog(@"*** CLOUDMINE: Attempting to register for push notifications requires a user that is logged in! The user is either not logged in, or nil!");
if (callback) {
Expand All @@ -249,7 +254,15 @@ - (void)registerForPushNotifications:(UIRemoteNotificationType)notificationType
delegate.callback = callback;
delegate.user = aUser;
delegate.service = self.webService;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:notificationType];

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationType categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:notificationType];
}
}

- (void)unRegisterForPushNotificationsWithCallback:(CMWebServiceDeviceTokenCallback)callback;
Expand Down

0 comments on commit 6aa9b97

Please sign in to comment.