summaryrefslogtreecommitdiff
path: root/Juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-03-27 02:50:06 +0300
committerGravatar Vitaly Takmazov2017-06-28 21:28:48 +0300
commitc5888b864756cc38e94f81850f52687cb7dd2c0c (patch)
tree1a861b1eb1161d133efdc1a35e68a343c2c03889 /Juick
parent9fd3a914fee6c22d7d7148ca100df72aa7cfc74e (diff)
push notifications
Diffstat (limited to 'Juick')
-rw-r--r--Juick/AppDelegate.m20
-rw-r--r--Juick/Model/Message.m1
-rw-r--r--Juick/Model/TokensList.h14
-rw-r--r--Juick/Model/TokensList.m13
-rw-r--r--Juick/Supporting Files/Juick-Info.plist2
-rw-r--r--Juick/Supporting Files/Juick-Prefix.pch8
6 files changed, 53 insertions, 5 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
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 <Foundation/Foundation.h>
+
+@interface TokensList : NSObject
+@property NSString *type;
+@property NSArray<NSString *> *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 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
- <string>1.0.14</string>
+ <string>1.0.16</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationCategoryType</key>
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 <AFNetworking/AFNetworking.h>
+ #import "NSString+FontAwesome.h"
+ @import TTTAttributedLabel;
+ @import AFNetworking;
+ @import YYModel;
#endif