From c5888b864756cc38e94f81850f52687cb7dd2c0c Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 27 Mar 2017 02:50:06 +0300 Subject: push notifications --- Juick/AppDelegate.m | 20 ++++++++++++++++++++ Juick/Model/Message.m | 1 + Juick/Model/TokensList.h | 14 ++++++++++++++ Juick/Model/TokensList.m | 13 +++++++++++++ Juick/Supporting Files/Juick-Info.plist | 2 +- Juick/Supporting Files/Juick-Prefix.pch | 8 ++++---- 6 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 Juick/Model/TokensList.h create mode 100644 Juick/Model/TokensList.m (limited to 'Juick') 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 diff --git a/Juick/Model/Message.m b/Juick/Model/Message.m index a7934ac..4a6e96c 100644 --- a/Juick/Model/Message.m +++ b/Juick/Model/Message.m @@ -25,6 +25,7 @@ +(void) pullNextFromPath:(NSString *)path params:(NSDictionary *) params callback:(void(^)(NSArray *))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"]]; } [manager GET:path parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { diff --git a/Juick/Model/TokensList.h b/Juick/Model/TokensList.h new file mode 100644 index 0000000..9ed5ab0 --- /dev/null +++ b/Juick/Model/TokensList.h @@ -0,0 +1,14 @@ +// +// TokensList.h +// Juick +// +// Created by Vitaly Takmazov on 27/03/2017. +// Copyright © 2017 com.juick. All rights reserved. +// + +#import + +@interface TokensList : NSObject +@property NSString *type; +@property NSArray *tokens; +@end diff --git a/Juick/Model/TokensList.m b/Juick/Model/TokensList.m new file mode 100644 index 0000000..5cfe6a6 --- /dev/null +++ b/Juick/Model/TokensList.m @@ -0,0 +1,13 @@ +// +// 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 0c481a1..ed5a794 100644 --- a/Juick/Supporting Files/Juick-Info.plist +++ b/Juick/Supporting Files/Juick-Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 1.0.14 + 1.0.16 ITSAppUsesNonExemptEncryption LSApplicationCategoryType diff --git a/Juick/Supporting Files/Juick-Prefix.pch b/Juick/Supporting Files/Juick-Prefix.pch index d88823b..ee9f226 100644 --- a/Juick/Supporting Files/Juick-Prefix.pch +++ b/Juick/Supporting Files/Juick-Prefix.pch @@ -18,8 +18,8 @@ #import "YYWebImage.h" #import "NSString+HTML.h" #import "UIImage+Utils.h" - #import "NSDate+TimeAgo.h" - #import "TTTAttributedLabel.h" - #import "SWRevealViewController.h" - #import + #import "NSString+FontAwesome.h" + @import TTTAttributedLabel; + @import AFNetworking; + @import YYModel; #endif -- cgit v1.2.3