diff options
-rw-r--r-- | Juick.xcodeproj/project.pbxproj | 17 | ||||
-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 |
9 files changed, 40 insertions, 34 deletions
diff --git a/Juick.xcodeproj/project.pbxproj b/Juick.xcodeproj/project.pbxproj index d2961f0..c6fa084 100644 --- a/Juick.xcodeproj/project.pbxproj +++ b/Juick.xcodeproj/project.pbxproj @@ -8,7 +8,6 @@ /* Begin PBXBuildFile section */ 274CA3F5A1521329BEA647FB /* Pods_Juick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EE63D145DADD14AE17A58456 /* Pods_Juick.framework */; }; - 770A42911E8881CB000B206A /* TokensList.m in Sources */ = {isa = PBXBuildFile; fileRef = 770A42901E8881CB000B206A /* TokensList.m */; }; 77317BAC181BBE8500D60005 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77317BAB181BBE8500D60005 /* Foundation.framework */; }; 77317BAE181BBE8500D60005 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77317BAD181BBE8500D60005 /* CoreGraphics.framework */; }; 77317BB0181BBE8500D60005 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77317BAF181BBE8500D60005 /* UIKit.framework */; }; @@ -61,8 +60,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 770A428F1E8881CB000B206A /* TokensList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TokensList.h; sourceTree = "<group>"; }; - 770A42901E8881CB000B206A /* TokensList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TokensList.m; sourceTree = "<group>"; }; + 770A428F1E8881CB000B206A /* DeviceRegistration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceRegistration.h; sourceTree = "<group>"; }; 77317BA8181BBE8500D60005 /* Juick.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Juick.app; sourceTree = BUILT_PRODUCTS_DIR; }; 77317BAB181BBE8500D60005 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 77317BAD181BBE8500D60005 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -96,6 +94,7 @@ 774528C41F93AC0F004D110B /* CoreDataStack.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CoreDataStack.m; sourceTree = "<group>"; }; 774528C91F93EE83004D110B /* AssetsLibrary.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AssetsLibrary.framework; path = System/Library/Frameworks/AssetsLibrary.framework; sourceTree = SDKROOT; }; 774528CB1F93EE9F004D110B /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; + 774528CD1F96B39C004D110B /* Juick.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Juick.entitlements; sourceTree = "<group>"; }; 77975A1B182B6E9A00410C2B /* NewPostViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NewPostViewController.h; sourceTree = "<group>"; }; 77975A1C182B6E9A00410C2B /* NewPostViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NewPostViewController.m; sourceTree = "<group>"; }; 77975A1E182BDCE900410C2B /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; @@ -200,6 +199,7 @@ 77317BB1181BBE8500D60005 /* Juick */ = { isa = PBXGroup; children = ( + 774528CD1F96B39C004D110B /* Juick.entitlements */, 773F23341F76ED5D00B5B0DF /* Splash.png */, 773F23351F76ED5D00B5B0DF /* Splash@2x.png */, 773F23361F76ED5E00B5B0DF /* Splash@3x.png */, @@ -261,8 +261,7 @@ 77A09549181F1F25002BDECD /* Message.m */, 77B099A4189D57F000A84F59 /* User.h */, 77B099A5189D57F000A84F59 /* User.m */, - 770A428F1E8881CB000B206A /* TokensList.h */, - 770A42901E8881CB000B206A /* TokensList.m */, + 770A428F1E8881CB000B206A /* DeviceRegistration.h */, 774528C01F930C06004D110B /* Attachment.h */, 774528C11F930C06004D110B /* Attachment.m */, ); @@ -367,6 +366,11 @@ TargetAttributes = { 77317BA7181BBE8500D60005 = { DevelopmentTeam = KH4MX79ZK7; + SystemCapabilities = { + com.apple.Push = { + enabled = 1; + }; + }; }; 77317BCB181BBE8500D60005 = { DevelopmentTeam = KH4MX79ZK7; @@ -521,7 +525,6 @@ 774528C51F93AC0F004D110B /* CoreDataStack.m in Sources */, 77B09994189D0B9900A84F59 /* UIImage+Utils.m in Sources */, 77317BC2181BBE8500D60005 /* MessagesViewController.m in Sources */, - 770A42911E8881CB000B206A /* TokensList.m in Sources */, 77B099A6189D57F000A84F59 /* User.m in Sources */, 77C6ADE41F7717BC000AEA8C /* ThreadViewController.m in Sources */, 77975A1D182B6E9A00410C2B /* NewPostViewController.m in Sources */, @@ -677,6 +680,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + CODE_SIGN_ENTITLEMENTS = Juick/Juick.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; DEVELOPMENT_TEAM = KH4MX79ZK7; @@ -698,6 +702,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + CODE_SIGN_ENTITLEMENTS = Juick/Juick.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "Juick/Supporting Files/Juick-Prefix.pch"; 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; |