|
|
@ -43,47 +43,6 @@
|
|
|
|
return self;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)registrationWithSuccess:(void (^)())success failure:(failedPushRegistrationBlock)failure{
|
|
|
|
|
|
|
|
if (!self.wantRemoteNotifications) {
|
|
|
|
|
|
|
|
success();
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[self registrationForPushWithSuccess:^(NSData* pushToken){
|
|
|
|
|
|
|
|
[self registrationForUserNotificationWithSuccess:success failure:^(NSError *error) {
|
|
|
|
|
|
|
|
[self.missingPermissionsAlertView show];
|
|
|
|
|
|
|
|
failure([NSError errorWithDomain:pushManagerDomain code:400 userInfo:@{}]);
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
} failure:failure];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark Private Methods
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark Register Push Notification Token with server
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-(TOCFuture*)registerForPushFutureWithToken:(NSData*)token{
|
|
|
|
|
|
|
|
self.registerWithServerFutureSource = [TOCFutureSource new];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[RPServerRequestsManager.sharedInstance performRequest:[RPAPICall registerPushNotificationWithPushToken:token] success:^(NSURLSessionDataTask *task, id responseObject) {
|
|
|
|
|
|
|
|
if ([task.response isKindOfClass: NSHTTPURLResponse.class]){
|
|
|
|
|
|
|
|
NSInteger statusCode = [(NSHTTPURLResponse*) task.response statusCode];
|
|
|
|
|
|
|
|
if (statusCode == 200) {
|
|
|
|
|
|
|
|
[self.registerWithServerFutureSource trySetResult:@YES];
|
|
|
|
|
|
|
|
} else{
|
|
|
|
|
|
|
|
DDLogError(@"The server returned %@ instead of a 200 status code", task.response);
|
|
|
|
|
|
|
|
[self.registerWithServerFutureSource trySetFailure:[NSError errorWithDomain:pushManagerDomain code:500 userInfo:nil]];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else{
|
|
|
|
|
|
|
|
[self.registerWithServerFutureSource trySetFailure:task.response];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} failure:^(NSURLSessionDataTask *task, NSError *error) {
|
|
|
|
|
|
|
|
[self.registerWithServerFutureSource trySetFailure:error];
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return self.registerWithServerFutureSource.future;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark Register device for Push Notification locally
|
|
|
|
#pragma mark Register device for Push Notification locally
|
|
|
|
|
|
|
|
|
|
|
|
-(TOCFuture*)registerPushNotificationFuture{
|
|
|
|
-(TOCFuture*)registerPushNotificationFuture{
|
|
|
@ -93,7 +52,7 @@
|
|
|
|
return self.pushNotificationFutureSource.future;
|
|
|
|
return self.pushNotificationFutureSource.future;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)registrationForPushWithSuccess:(void (^)(NSData* pushToken))success failure:(failedPushRegistrationBlock)failure{
|
|
|
|
- (void)requestPushTokenWithSuccess:(void (^)(NSData* pushToken))success failure:(failedPushRegistrationBlock)failure{
|
|
|
|
TOCFuture *requestPushTokenFuture = [self registerPushNotificationFuture];
|
|
|
|
TOCFuture *requestPushTokenFuture = [self registerPushNotificationFuture];
|
|
|
|
|
|
|
|
|
|
|
|
[requestPushTokenFuture catchDo:^(id failureObj) {
|
|
|
|
[requestPushTokenFuture catchDo:^(id failureObj) {
|
|
|
@ -110,13 +69,22 @@
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
[registerPushTokenFuture thenDo:^(id value) {
|
|
|
|
[registerPushTokenFuture thenDo:^(id value) {
|
|
|
|
success(pushToken);
|
|
|
|
TOCFuture *userRegistration = [self registerForUserNotificationsFuture];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[userRegistration thenDo:^(UIUserNotificationSettings *userNotificationSettings) {
|
|
|
|
|
|
|
|
success(pushToken);
|
|
|
|
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)registrationAndRedPhoneTokenRequestWithSuccess:(void (^)(NSData* pushToken, NSString* signupToken))success failure:(failedPushRegistrationBlock)failure{
|
|
|
|
- (void)registrationAndRedPhoneTokenRequestWithSuccess:(void (^)(NSData* pushToken, NSString* signupToken))success failure:(failedPushRegistrationBlock)failure{
|
|
|
|
[self registrationForPushWithSuccess:^(NSData *pushToken) {
|
|
|
|
if (!self.wantRemoteNotifications) {
|
|
|
|
|
|
|
|
success([@"Fake PushToken" dataUsingEncoding:NSUTF8StringEncoding], @"");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[self requestPushTokenWithSuccess:^(NSData* pushToken){
|
|
|
|
[RPServerRequestsManager.sharedInstance performRequest:[RPAPICall requestTextSecureVerificationCode] success:^(NSURLSessionDataTask *task, id responseObject) {
|
|
|
|
[RPServerRequestsManager.sharedInstance performRequest:[RPAPICall requestTextSecureVerificationCode] success:^(NSURLSessionDataTask *task, id responseObject) {
|
|
|
|
NSError *error;
|
|
|
|
NSError *error;
|
|
|
|
|
|
|
|
|
|
|
@ -132,7 +100,10 @@
|
|
|
|
} failure:^(NSURLSessionDataTask *task, NSError *error) {
|
|
|
|
} failure:^(NSURLSessionDataTask *task, NSError *error) {
|
|
|
|
failure(error);
|
|
|
|
failure(error);
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
} failure:failure];
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
[self.missingPermissionsAlertView show];
|
|
|
|
|
|
|
|
failure([NSError errorWithDomain:pushManagerDomain code:400 userInfo:@{}]);
|
|
|
|
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-(TOCFuture*)registerForUserNotificationsFuture{
|
|
|
|
-(TOCFuture*)registerForUserNotificationsFuture{
|
|
|
@ -143,18 +114,6 @@
|
|
|
|
return self.userNotificationFutureSource.future;
|
|
|
|
return self.userNotificationFutureSource.future;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)registrationForUserNotificationWithSuccess:(void (^)())success failure:(void (^)())failure{
|
|
|
|
|
|
|
|
TOCFuture *registrerUserNotificationFuture = [self registerForUserNotificationsFuture];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[registrerUserNotificationFuture catchDo:^(id failureObj) {
|
|
|
|
|
|
|
|
failure();
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[registrerUserNotificationFuture thenDo:^(id types) {
|
|
|
|
|
|
|
|
success();
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-(BOOL) needToRegisterForRemoteNotifications {
|
|
|
|
-(BOOL) needToRegisterForRemoteNotifications {
|
|
|
|
return self.wantRemoteNotifications && (!UIApplication.sharedApplication.isRegisteredForRemoteNotifications);
|
|
|
|
return self.wantRemoteNotifications && (!UIApplication.sharedApplication.isRegisteredForRemoteNotifications);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -174,4 +133,35 @@
|
|
|
|
return UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge;
|
|
|
|
return UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)validateUserNotificationSettings{
|
|
|
|
|
|
|
|
[[self registerForUserNotificationsFuture] thenDo:^(id value) {
|
|
|
|
|
|
|
|
//Nothing to do, just making sure we are registered for User Notifications.
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark Register Push Notification Token with RedPhone server
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-(TOCFuture*)registerForPushFutureWithToken:(NSData*)token{
|
|
|
|
|
|
|
|
self.registerWithServerFutureSource = [TOCFutureSource new];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[RPServerRequestsManager.sharedInstance performRequest:[RPAPICall registerPushNotificationWithPushToken:token] success:^(NSURLSessionDataTask *task, id responseObject) {
|
|
|
|
|
|
|
|
if ([task.response isKindOfClass: NSHTTPURLResponse.class]){
|
|
|
|
|
|
|
|
NSInteger statusCode = [(NSHTTPURLResponse*) task.response statusCode];
|
|
|
|
|
|
|
|
if (statusCode == 200) {
|
|
|
|
|
|
|
|
[self.registerWithServerFutureSource trySetResult:@YES];
|
|
|
|
|
|
|
|
} else{
|
|
|
|
|
|
|
|
DDLogError(@"The server returned %@ instead of a 200 status code", task.response);
|
|
|
|
|
|
|
|
[self.registerWithServerFutureSource trySetFailure:[NSError errorWithDomain:pushManagerDomain code:500 userInfo:nil]];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else{
|
|
|
|
|
|
|
|
[self.registerWithServerFutureSource trySetFailure:task.response];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} failure:^(NSURLSessionDataTask *task, NSError *error) {
|
|
|
|
|
|
|
|
[self.registerWithServerFutureSource trySetFailure:error];
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return self.registerWithServerFutureSource.future;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
@end
|
|
|
|