summaryrefslogtreecommitdiff
path: root/Juick/AppDelegate.m
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/AppDelegate.m')
-rw-r--r--Juick/AppDelegate.m20
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