From c5888b864756cc38e94f81850f52687cb7dd2c0c Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 27 Mar 2017 02:50:06 +0300 Subject: push notifications --- Juick/AppDelegate.m | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'Juick/AppDelegate.m') diff --git a/Juick/AppDelegate.m b/Juick/AppDelegate.m index 8240892..1ba0ccf 100644 --- a/Juick/AppDelegate.m +++ b/Juick/AppDelegate.m @@ -14,6 +14,7 @@ #import "ColorScheme.h" #import "Message.h" +#import "TokensList.h" @implementation AppDelegate @@ -45,6 +46,7 @@ SWRevealViewController *reveal; [User checkIsValid:^(BOOL success) { if (success) { [messages loadFromPath:[Message feedUrl] withParams:nil withTitle:@"My feed"]; + [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert|UIUserNotificationTypeSound|UIUserNotificationTypeBadge) categories:nil]]; } else { [User throwUnableToLogin]; } @@ -69,4 +71,22 @@ SWRevealViewController *reveal; [messages pushViewController:loginView animated:YES]; } +-(void) application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { + [[UIApplication sharedApplication] registerForRemoteNotifications]; +} + +-(void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { + NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]]; + token = [token stringByReplacingOccurrencesOfString:@" " withString:@""]; + TokensList *tokensList = [TokensList new]; + tokensList.type = @"apns"; + tokensList.tokens = [NSArray arrayWithObjects:token, nil]; + AFHTTPSessionManager *manager = [APIClient sharedClient].manager; + [manager PUT:@"/notifications" parameters:[tokensList yy_modelToJSONObject] success:nil failure:nil]; +} + +-(void) application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { + NSLog(@"Error: %@", [error debugDescription]); +} + @end -- cgit v1.2.3