diff options
author | Vitaly Takmazov | 2017-10-18 01:48:34 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-10-18 01:48:34 +0300 |
commit | 2345989ce454342d8ac45077e2cd650d18744066 (patch) | |
tree | a1c529b1dadab49c76b82da80044cc4a80d32ec0 /Juick | |
parent | 07afcd6f36629f30a495f2be47262c75c006712f (diff) |
device registration
Diffstat (limited to 'Juick')
-rw-r--r-- | Juick/APIClient.m | 5 | ||||
-rw-r--r-- | Juick/AppDelegate.h | 2 | ||||
-rw-r--r-- | Juick/AppDelegate.m | 21 | ||||
-rw-r--r-- | Juick/Juick.entitlements | 2 | ||||
-rw-r--r-- | Juick/Model/DeviceRegistration.h (renamed from Juick/Model/TokensList.h) | 7 | ||||
-rw-r--r-- | Juick/Model/TokensList.m | 13 | ||||
-rw-r--r-- | Juick/Supporting Files/Juick-Info.plist | 2 | ||||
-rw-r--r-- | Juick/ViewControllers/LoginViewController.m | 5 |
8 files changed, 29 insertions, 28 deletions
diff --git a/Juick/APIClient.m b/Juick/APIClient.m index d2356b5..beace7c 100644 --- a/Juick/APIClient.m +++ b/Juick/APIClient.m @@ -23,16 +23,13 @@ -(id)init { if (self = [super init]) { self.manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:@"https://api.juick.com"]]; + self.manager.requestSerializer = [AFJSONRequestSerializer new]; } return self; } -(void) pullNextFromPath:(NSString *)path params:(NSDictionary *) params callback:(void(^)(NSArray *, NSError *))callback { AFHTTPSessionManager *manager = [APIClient sharedClient].manager; - if ([[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"] != nil) { - manager.requestSerializer = [AFJSONRequestSerializer serializer]; - [manager.requestSerializer setAuthorizationHeaderFieldWithUsername:[[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"] password:[[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.password"]]; - } dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [manager GET:path parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { NSMutableArray *messages = [NSMutableArray new]; diff --git a/Juick/AppDelegate.h b/Juick/AppDelegate.h index b5954e1..64cc01a 100644 --- a/Juick/AppDelegate.h +++ b/Juick/AppDelegate.h @@ -13,4 +13,6 @@ @property (strong, nonatomic) UIWindow *window; +-(void) registerForRemoteNotifications; + @end 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 { diff --git a/Juick/Juick.entitlements b/Juick/Juick.entitlements index 28c29bf..903def2 100644 --- a/Juick/Juick.entitlements +++ b/Juick/Juick.entitlements @@ -3,6 +3,6 @@ <plist version="1.0"> <dict> <key>aps-environment</key> - <string>production</string> + <string>development</string> </dict> </plist> diff --git a/Juick/Model/TokensList.h b/Juick/Model/DeviceRegistration.h index 9ed5ab0..e629637 100644 --- a/Juick/Model/TokensList.h +++ b/Juick/Model/DeviceRegistration.h @@ -8,7 +8,10 @@ #import <Foundation/Foundation.h> -@interface TokensList : NSObject +@interface DeviceRegistration : NSObject @property NSString *type; -@property NSArray<NSString *> *tokens; +@property NSString *token; +@end + +@implementation DeviceRegistration @end diff --git a/Juick/Model/TokensList.m b/Juick/Model/TokensList.m deleted file mode 100644 index 5cfe6a6..0000000 --- a/Juick/Model/TokensList.m +++ /dev/null @@ -1,13 +0,0 @@ -// -// TokensList.m -// Juick -// -// Created by Vitaly Takmazov on 27/03/2017. -// Copyright © 2017 com.juick. All rights reserved. -// - -#import "TokensList.h" - -@implementation TokensList - -@end diff --git a/Juick/Supporting Files/Juick-Info.plist b/Juick/Supporting Files/Juick-Info.plist index 74fbe61..e3ddfc5 100644 --- a/Juick/Supporting Files/Juick-Info.plist +++ b/Juick/Supporting Files/Juick-Info.plist @@ -21,7 +21,7 @@ <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> - <string>1.0.19</string> + <string>1.0.20</string> <key>ITSAppUsesNonExemptEncryption</key> <false/> <key>LSApplicationCategoryType</key> diff --git a/Juick/ViewControllers/LoginViewController.m b/Juick/ViewControllers/LoginViewController.m index 1718366..d3d1edc 100644 --- a/Juick/ViewControllers/LoginViewController.m +++ b/Juick/ViewControllers/LoginViewController.m @@ -9,6 +9,7 @@ #import "LoginViewController.h" #import "User.h" #import "ColorScheme.h" +#import "AppDelegate.h" @implementation LoginViewController @@ -57,6 +58,10 @@ - (void) doneSignIn { [User checkIsValid:^(BOOL success) { if (success) { + [[APIClient sharedClient].manager.requestSerializer setAuthorizationHeaderFieldWithUsername:[[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"] password:[[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.password"]]; + + AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate]; + [app registerForRemoteNotifications]; CATransition* transition = [CATransition animation]; transition.duration = 0.3; transition.type = kCATransitionFade; |