summaryrefslogtreecommitdiff
path: root/Juick/AppDelegate.m
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/AppDelegate.m')
-rw-r--r--Juick/AppDelegate.m21
1 files changed, 14 insertions, 7 deletions
diff --git a/Juick/AppDelegate.m b/Juick/AppDelegate.m
index 7be4424..d4f0b8c 100644
--- a/Juick/AppDelegate.m
+++ b/Juick/AppDelegate.m
@@ -12,7 +12,7 @@
#import "ColorScheme.h"
#import "Message.h"
-#import "TokensList.h"
+#import "DeviceRegistration.h"
#import "NewPostViewController.h"
@implementation AppDelegate
@@ -25,7 +25,8 @@
[[UIToolbar appearance] setTintColor:[ColorScheme linkColor]];
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
-
+
+ [self registerForRemoteNotifications];
return YES;
}
@@ -34,7 +35,9 @@
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
if(!error){
- [[UIApplication sharedApplication] registerForRemoteNotifications];
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+ [[UIApplication sharedApplication] registerForRemoteNotifications];
+ }];
}
}];
}
@@ -42,11 +45,15 @@
-(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];
+ DeviceRegistration *registration = [DeviceRegistration new];
+ registration.type = @"apns";
+ registration.token = token;
AFHTTPSessionManager *manager = [APIClient sharedClient].manager;
- [manager PUT:@"/notifications" parameters:[tokensList yy_modelToJSONObject] success:nil failure:nil];
+ [manager PUT:@"/notifications" parameters:[@[registration] yy_modelToJSONObject] success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
+ NSLog(@"success");
+ } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
+ NSLog(@"fail %@", [error localizedDescription]);
+ } ];
}
-(void) application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {