Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean iOS 9 warnings #172

Merged
merged 4 commits into from
Sep 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Pod/Classes/Core/A0APIv1Router.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ - (NSString *)usersPath {
}

- (NSString *)userPublicKeyPathForUser:(NSString *)userId {
return [[NSString stringWithFormat:@"api/users/%@/publickey", userId] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];;
return [[NSString stringWithFormat:@"api/users/%@/publickey", userId] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]];;
}

- (NSString *)startPasswordless {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// A0UIUtilities.h
// A0Alert.h
//
// Copyright (c) 2014 Auth0 (http://auth0.com)
// Copyright (c) 2015 Auth0 (http://auth0.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -22,4 +22,20 @@

#import <Foundation/Foundation.h>

void A0ShowAlertErrorView(NSString *title, NSString *message);
NS_ASSUME_NONNULL_BEGIN
typedef void(^A0AlertButtonCallback)();

@interface A0Alert : NSObject

@property (copy, nonatomic) NSString *title;
@property (copy, nullable, nonatomic) NSString *message;
@property (copy, nullable, nonatomic) NSString *cancelTitle;

- (void)addButtonWithTitle:(NSString *)title callback:(nullable A0AlertButtonCallback)callback;
- (void)showInController:(UIViewController *)controller;

+ (A0Alert *)showInController:(UIViewController *)controller alert:(void(^)(A0Alert *alert))builder;
+ (A0Alert *)showInController:(UIViewController *)controller errorAlert:(void (^)(A0Alert * _Nonnull))builder;
@end

NS_ASSUME_NONNULL_END
112 changes: 112 additions & 0 deletions Pod/Classes/CoreUI/A0Alert.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// A0Alert.m
//
// Copyright (c) 2015 Auth0 (http://auth0.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#import "A0Alert.h"

@interface A0Alert () <UIAlertViewDelegate>
@property (strong, nonatomic) NSMutableDictionary<NSString *, A0AlertButtonCallback> *callbacks;
@property (strong, nonatomic) NSMutableArray<NSString *> *buttons;
@end

@implementation A0Alert

- (instancetype)init {
self = [super init];
if (self) {
_callbacks = [@{} mutableCopy];
}
return self;
}

- (void)addButtonWithTitle:(NSString *)title callback:(A0AlertButtonCallback)callback {
self.callbacks[title] = [callback copy];
[self.buttons addObject:title];
}

- (void)showInController:(UIViewController *)controller {
if ([UIAlertController class]) {
[self showAlerControllerFrom:controller];
} else {
[self showAlertView];
}
}

+ (A0Alert *)showInController:(UIViewController *)controller alert:(void(^)(A0Alert *alert))builder {
A0Alert *alert = [[A0Alert alloc] init];
if (builder) {
builder(alert);
}
[alert showInController:controller];
return alert;
}

+ (A0Alert *)showInController:(UIViewController *)controller errorAlert:(void (^)(A0Alert * _Nonnull))builder {
A0Alert *alert = [[A0Alert alloc] init];
alert.cancelTitle = A0LocalizedString(@"OK");
if (builder) {
builder(alert);
}
[alert showInController:controller];
return alert;
}

- (void)showAlerControllerFrom:(UIViewController *)controller {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:self.title message:self.message preferredStyle:UIAlertControllerStyleAlert];
if (self.cancelTitle) {
UIAlertAction *cancel = [UIAlertAction actionWithTitle:self.cancelTitle style:UIAlertActionStyleCancel handler:nil];
[alert addAction:cancel];
}
[self.buttons enumerateObjectsUsingBlock:^(NSString * _Nonnull title, NSUInteger idx, BOOL * _Nonnull stop) {
A0AlertButtonCallback callback = self.callbacks[title];
UIAlertAction *action = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if (callback) {
callback();
}
}];
[alert addAction:action];
}];
[controller presentViewController:alert animated:YES completion:nil];
}

- (void)showAlertView {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:self.title
message:self.message
delegate:self
cancelButtonTitle:self.cancelTitle
otherButtonTitles:nil];
#pragma clang diagnostic pop
[self.buttons enumerateObjectsUsingBlock:^(NSString * _Nonnull title, NSUInteger idx, BOOL * _Nonnull stop) {
[alert addButtonWithTitle:title];
}];
[alert show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *title = self.buttons[buttonIndex];
A0AlertButtonCallback callback = self.callbacks[title];
if (callback) {
callback();
}
}
@end
12 changes: 9 additions & 3 deletions Pod/Classes/Email/Private/A0EmailCodeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#import "A0CredentialFieldView.h"
#import "A0ProgressButton.h"
#import "A0Theme.h"
#import "A0UIUtilities.h"
#import "A0Alert.h"
#import "A0APIClient.h"
#import "A0Errors.h"

Expand Down Expand Up @@ -86,7 +86,10 @@ - (void)login:(id)sender {
[self.loginButton setInProgress:NO];
NSString *title = [error a0_auth0ErrorWithCode:A0ErrorCodeNotConnectedToInternet] ? error.localizedDescription : A0LocalizedString(@"There was an error logging in");
NSString *message = [error a0_auth0ErrorWithCode:A0ErrorCodeNotConnectedToInternet] ? error.localizedFailureReason : [A0Errors localizedStringForSMSLoginError:error];
A0ShowAlertErrorView(title, message);
[A0Alert showInController:self errorAlert:^(A0Alert *alert) {
alert.title = title;
alert.message = message;
}];
};
[self.loginButton setInProgress:YES];
A0APIClient *client = [self a0_apiClientFromProvider:self.lock];
Expand All @@ -97,7 +100,10 @@ - (void)login:(id)sender {
failure:failureBlock];
} else {
A0LogError(@"Must provide a non-empty passcode.");
A0ShowAlertErrorView(A0LocalizedString(@"There was an error logging in"), A0LocalizedString(@"You must enter a valid email code"));
[A0Alert showInController:self errorAlert:^(A0Alert *alert) {
alert.title = A0LocalizedString(@"There was an error logging in");
alert.message = A0LocalizedString(@"You must enter a valid email code");
}];
}
}

Expand Down
12 changes: 9 additions & 3 deletions Pod/Classes/Email/Private/A0EmailSendCodeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#import "A0APIClient.h"
#import "A0RequestAccessTokenOperation.h"
#import "A0SendSMSOperation.h"
#import "A0UIUtilities.h"
#import "A0Alert.h"
#import "A0EmailValidator.h"
#import "A0Errors.h"
#import "A0Lock.h"
Expand Down Expand Up @@ -85,7 +85,10 @@ - (void)registerSMS:(id)sender {
A0LogError(@"Failed to send SMS code with error %@", error);
NSString *title = [error a0_auth0ErrorWithCode:A0ErrorCodeNotConnectedToInternet] ? error.localizedDescription : A0LocalizedString(@"There was an error sending the email code");
NSString *message = [error a0_auth0ErrorWithCode:A0ErrorCodeNotConnectedToInternet] ? error.localizedFailureReason : A0LocalizedString(@"Couldn't send the email with your login code. Please try again later.");
A0ShowAlertErrorView(title, message);
[A0Alert showInController:self errorAlert:^(A0Alert *alert) {
alert.title = title;
alert.message = message;
}];
[self.registerButton setInProgress:NO];
};
A0LogDebug(@"About to send Email code to %@", phoneNumber);
Expand All @@ -100,7 +103,10 @@ - (void)registerSMS:(id)sender {
} failure:onFailure];
} else {
[self.emailFieldView setInvalid:YES];
A0ShowAlertErrorView(error.localizedDescription, error.localizedFailureReason);
[A0Alert showInController:self errorAlert:^(A0Alert *alert) {
alert.title = error.localizedDescription;
alert.message = error.localizedFailureReason;
}];
}
}

Expand Down
12 changes: 9 additions & 3 deletions Pod/Classes/SMS/Private/A0SMSCodeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#import "A0CredentialFieldView.h"
#import "A0ProgressButton.h"
#import "A0Theme.h"
#import "A0UIUtilities.h"
#import "A0Alert.h"
#import "A0APIClient.h"
#import "A0Errors.h"

Expand Down Expand Up @@ -86,7 +86,10 @@ - (void)login:(id)sender {
[self.loginButton setInProgress:NO];
NSString *title = [error a0_auth0ErrorWithCode:A0ErrorCodeNotConnectedToInternet] ? error.localizedDescription : A0LocalizedString(@"There was an error logging in");
NSString *message = [error a0_auth0ErrorWithCode:A0ErrorCodeNotConnectedToInternet] ? error.localizedFailureReason : [A0Errors localizedStringForSMSLoginError:error];
A0ShowAlertErrorView(title, message);
[A0Alert showInController:self errorAlert:^(A0Alert *alert) {
alert.title = title;
alert.message = message;
}];
};
[self.loginButton setInProgress:YES];
A0APIClient *client = [self a0_apiClientFromProvider:self.lock];
Expand All @@ -97,7 +100,10 @@ - (void)login:(id)sender {
failure:failureBlock];
} else {
A0LogError(@"Must provide a non-empty passcode.");
A0ShowAlertErrorView(A0LocalizedString(@"There was an error logging in"), A0LocalizedString(@"You must enter a valid SMS code"));
[A0Alert showInController:self errorAlert:^(A0Alert *alert) {
alert.title = A0LocalizedString(@"There was an error logging in");
alert.message = A0LocalizedString(@"You must enter a valid SMS code");
}];
}
}

Expand Down
12 changes: 9 additions & 3 deletions Pod/Classes/SMS/Private/A0SMSSendCodeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#import "A0APIClient.h"
#import "A0RequestAccessTokenOperation.h"
#import "A0SendSMSOperation.h"
#import "A0UIUtilities.h"
#import "A0Alert.h"

#import <libextobjc/EXTScope.h>
#import "A0Errors.h"
Expand Down Expand Up @@ -101,7 +101,10 @@ - (void)registerSMS:(id)sender {
A0LogError(@"Failed to send SMS code with error %@", error);
NSString *title = [error a0_auth0ErrorWithCode:A0ErrorCodeNotConnectedToInternet] ? error.localizedDescription : A0LocalizedString(@"There was an error sending the SMS code");
NSString *message = [error a0_auth0ErrorWithCode:A0ErrorCodeNotConnectedToInternet] ? error.localizedFailureReason : A0LocalizedString(@"Couldn't send an SMS to your phone. Please try again later.");
A0ShowAlertErrorView(title, message);
[A0Alert showInController:self errorAlert:^(A0Alert *alert) {
alert.title = title;
alert.message = message;
}];
[self.registerButton setInProgress:NO];
};
A0LogDebug(@"About to send SMS code to phone %@", phoneNumber);
Expand All @@ -117,7 +120,10 @@ - (void)registerSMS:(id)sender {
} else {
A0LogError(@"No phone number provided");
[self.phoneFieldView setInvalid:YES];
A0ShowAlertErrorView(A0LocalizedString(@"There was an error sending the SMS code"), A0LocalizedString(@"You must enter a valid phone number"));
[A0Alert showInController:self errorAlert:^(A0Alert *alert) {
alert.title = A0LocalizedString(@"There was an error sending the SMS code");
alert.message = A0LocalizedString(@"You must enter a valid phone number");
}];
}
}

Expand Down
12 changes: 6 additions & 6 deletions Pod/Classes/TouchID/A0TouchIDLockViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#import "A0Lock.h"
#import "NSObject+A0APIClientProvider.h"
#import "UIConstants.h"
#import "A0Alert.h"

NSString * const A0ThemeTouchIDLockButtonImageNormalName = @"A0ThemeTouchIDLockButtonImageNormalName";
NSString * const A0ThemeTouchIDLockButtonImageHighlightedName = @"A0ThemeTouchIDLockButtonImageHighlightedName";
Expand Down Expand Up @@ -135,12 +136,11 @@ - (void)viewDidLoad {
message = A0LocalizedString(@"Couldn't authenticate with TouchID. Please try again later!.");
break;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:A0LocalizedString(@"There was an error logging in")
message:message
delegate:nil
cancelButtonTitle:A0LocalizedString(@"OK")
otherButtonTitles:nil];
[alert show];
[A0Alert showInController:self alert:^(A0Alert *alert) {
alert.title = A0LocalizedString(@"There was an error logging in");
alert.message = message;
alert.cancelTitle = A0LocalizedString(@"OK");
}];
self.touchIDView.hidden = NO;
self.loadingView.hidden = YES;
};
Expand Down
12 changes: 9 additions & 3 deletions Pod/Classes/TouchID/Private/A0TouchIDSignUpViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#import "A0ProgressButton.h"
#import "A0APIClient.h"
#import "A0Errors.h"
#import "A0UIUtilities.h"
#import "A0Alert.h"

#import <libextobjc/EXTScope.h>
#import "A0EmailValidator.h"
Expand Down Expand Up @@ -97,11 +97,17 @@ - (void)signUp:(id)sender {
[self.signUpButton setInProgress:NO];
NSString *title = [error a0_auth0ErrorWithCode:A0ErrorCodeNotConnectedToInternet] ? error.localizedDescription : A0LocalizedString(@"There was an error signing up");
NSString *message = [error a0_auth0ErrorWithCode:A0ErrorCodeNotConnectedToInternet] ? error.localizedFailureReason : [A0Errors localizedStringForSignUpError:error];
A0ShowAlertErrorView(title, message);
[A0Alert showInController:self errorAlert:^(A0Alert *alert) {
alert.title = title;
alert.message = message;
}];
}];
} else {
[self.signUpButton setInProgress:NO];
A0ShowAlertErrorView(error.localizedDescription, error.localizedFailureReason);
[A0Alert showInController:self errorAlert:^(A0Alert *alert) {
alert.title = error.localizedDescription;
alert.message = error.localizedFailureReason;
}];
}
[self updateUIWithError:error];
}
Expand Down
27 changes: 14 additions & 13 deletions Pod/Classes/UI/A0LockSignUpViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
#import <libextobjc/EXTScope.h>
#import "A0Errors.h"
#import "A0SignUpViewController.h"
#import "A0UIUtilities.h"
#import "A0Alert.h"
#import "A0TitleView.h"
#import "A0Lock.h"
#import "NSObject+A0APIClientProvider.h"
#import "NSObject+A0AuthenticatorProvider.h"
#import "NSError+A0APIError.h"
#import "UIConstants.h"
#import "A0Alert.h"

@interface A0LockSignUpViewController () <A0SmallSocialServiceCollectionViewDelegate>

Expand Down Expand Up @@ -141,7 +142,10 @@ - (void)socialServiceCollectionView:(A0SmallSocialServiceCollectionView *)collec

- (void)socialServiceCollectionView:(A0SmallSocialServiceCollectionView *)collectionView
didFailWithError:(NSError *)error {
A0ShowAlertErrorView(error.localizedDescription, error.localizedFailureReason);
[A0Alert showInController:self errorAlert:^(A0Alert *alert) {
alert.title = error.localizedDescription;
alert.message = error.localizedFailureReason;
}];
}

- (void)authenticationDidStartForSocialCollectionView:(A0SmallSocialServiceCollectionView *)collectionView {
Expand Down Expand Up @@ -198,20 +202,17 @@ - (void)loadApplicationInfo {
A0LogError(@"Failed to fetch App info %@", error);
NSString *title = [error a0_auth0ErrorWithCode:A0ErrorCodeNotConnectedToInternet] ? error.localizedDescription : A0LocalizedString(@"Failed to display Sign Up");
NSString *message = [error a0_auth0ErrorWithCode:A0ErrorCodeNotConnectedToInternet] ? error.localizedFailureReason : A0LocalizedString(@"Couldnt get Sign Up screen configuration. Please try again.");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:nil
otherButtonTitles:A0LocalizedString(@"Retry"), nil];
[alert show];
[A0Alert showInController:self alert:^(A0Alert *alert) {
alert.title = title;
alert.message = message;
[alert addButtonWithTitle:A0LocalizedString(@"Retry") callback:^{
A0LogVerbose(@"Retrying fetch Auth0 app info...");
[self loadApplicationInfo];
}];
}];
}];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
A0LogVerbose(@"Retrying fetch Auth0 app info...");
[self loadApplicationInfo];
}

- (A0AuthParameters *)copyAuthenticationParameters {
A0AuthParameters *parameters = self.authenticationParameters ?: [A0AuthParameters newDefaultParams];
return parameters.copy;
Expand Down
Loading