diff options
author | Vitaly Takmazov | 2017-03-27 02:50:06 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-06-28 21:28:48 +0300 |
commit | c5888b864756cc38e94f81850f52687cb7dd2c0c (patch) | |
tree | 1a861b1eb1161d133efdc1a35e68a343c2c03889 /Juick/AppDelegate.m | |
parent | 9fd3a914fee6c22d7d7148ca100df72aa7cfc74e (diff) |
push notifications
Diffstat (limited to 'Juick/AppDelegate.m')
-rw-r--r-- | Juick/AppDelegate.m | 20 |
1 files changed, 20 insertions, 0 deletions
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 |