Use UIAlertController when available

This commit is contained in:
Andreas Linde
2015-07-22 15:37:51 +02:00
parent 29acf3ef05
commit cb00038222
9 changed files with 681 additions and 168 deletions

View File

@@ -291,12 +291,33 @@
if(succeeded) {
//controller should dismiss us shortly..
} else {
// requires iOS 8
id uialertcontrollerClass = NSClassFromString(@"UIAlertController");
if (uialertcontrollerClass) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
message:error.localizedDescription
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"OK")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {}];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil
message:error.localizedDescription
delegate:nil
cancelButtonTitle:BITHockeyLocalizedString(@"OK")
otherButtonTitles:nil];
[alertView show];
#pragma clang diagnostic pop
}
typeof(self) strongSelf = weakSelf;
[strongSelf setLoginUIEnabled:YES];
}

View File

@@ -256,6 +256,29 @@ static unsigned char kBITPNGEndChunk[4] = {0x49, 0x45, 0x4e, 0x44};
} else {
BITHockeyLog(@"Validation failed with error: %@", error);
// requires iOS 8
id uialertcontrollerClass = NSClassFromString(@"UIAlertController");
if (uialertcontrollerClass) {
__weak typeof(self) weakSelf = self;
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
message:error.localizedDescription
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"HockeyOK")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
[strongSelf validate];
}];
[alertController addAction:okAction];
[self showView:alertController];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil
message:error.localizedDescription
delegate:self
@@ -263,6 +286,8 @@ static unsigned char kBITPNGEndChunk[4] = {0x49, 0x45, 0x4e, 0x44};
otherButtonTitles:nil];
[alertView setTag:0];
[alertView show];
#pragma clang diagnostic pop
}
}
}];
}
@@ -906,11 +931,16 @@ static unsigned char kBITPNGEndChunk[4] = {0x49, 0x45, 0x4e, 0x44};
}
#pragma mark - UIAlertViewDelegate
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (alertView.tag == 0) {
[self validate];
}
}
#pragma clang diagnostic pop
@end
#endif

View File

@@ -1045,6 +1045,50 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
if (_alertViewHandler) {
_alertViewHandler();
} else {
// requires iOS 8
id uialertcontrollerClass = NSClassFromString(@"UIAlertController");
if (uialertcontrollerClass) {
__weak typeof(self) weakSelf = self;
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:BITHockeyLocalizedString(@"CrashDataFoundTitle"), appName]
message:alertDescription
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"CrashDontSendReport")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
[strongSelf handleUserInput:BITCrashManagerUserInputDontSend withUserProvidedMetaData:nil];
}];
[alertController addAction:cancelAction];
UIAlertAction *sendAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"CrashSendReport")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
[strongSelf handleUserInput:BITCrashManagerUserInputSend withUserProvidedMetaData:nil];
}];
[alertController addAction:sendAction];
if (self.shouldShowAlwaysButton) {
UIAlertAction *alwaysSendAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"CrashSendReportAlways")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
[strongSelf handleUserInput:BITCrashManagerUserInputAlwaysSend withUserProvidedMetaData:nil];
}];
[alertController addAction:alwaysSendAction];
}
[self showView:alertController];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:BITHockeyLocalizedString(@"CrashDataFoundTitle"), appName]
message:alertDescription
delegate:self
@@ -1056,6 +1100,8 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
}
[alertView show];
#pragma clang diagnostic pop
}
}
} else {
[self approveLatestCrashReport];
@@ -1451,6 +1497,8 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
#pragma mark - UIAlertView Delegate
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
case 0:
@@ -1464,8 +1512,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
break;
}
}
#pragma clang diagnostic pop
#pragma mark - Networking

View File

@@ -536,6 +536,47 @@
self.selectedAttachmentIndex = (self.attachmentScrollViewImageViews.count - index - 1);
// requires iOS 8
id uialertcontrollerClass = NSClassFromString(@"UIAlertController");
if (uialertcontrollerClass) {
__weak typeof(self) weakSelf = self;
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"HockeyFeedbackComposeAttachmentCancel")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
[strongSelf cancelAction];
}];
[alertController addAction:cancelAction];
UIAlertAction *editAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"HockeyFeedbackComposeAttachmentEdit")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
[strongSelf editAction];
}];
[alertController addAction:editAction];
UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"HockeyFeedbackComposeAttachmentDelete")
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
[strongSelf deleteAction];
}];
[alertController addAction:deleteAction];
[self presentViewController:alertController animated:YES completion:nil];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle: nil
delegate: self
cancelButtonTitle: BITHockeyLocalizedString(@"HockeyFeedbackComposeAttachmentCancel")
@@ -543,6 +584,8 @@
otherButtonTitles: BITHockeyLocalizedString(@"HockeyFeedbackComposeAttachmentEdit"), nil];
[actionSheet showFromRect: sender.frame inView: self.attachmentScrollView animated: YES];
#pragma clang diagnostic push
}
_actionSheetVisible = YES;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
@@ -587,9 +630,7 @@
#pragma mark - UIActionSheet Delegate
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == [actionSheet destructiveButtonIndex]) {
- (void)deleteAction {
if (self.selectedAttachmentIndex != NSNotFound){
UIButton *imageButton = self.attachmentScrollViewImageViews[self.selectedAttachmentIndex];
BITFeedbackMessageAttachment *attachment = self.imageAttachments[self.selectedAttachmentIndex];
@@ -606,7 +647,9 @@
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[self.textView becomeFirstResponder];
}
} else if (buttonIndex != [actionSheet cancelButtonIndex]) {
}
- (void)editAction {
if (self.selectedAttachmentIndex != NSNotFound){
BITFeedbackMessageAttachment *attachment = self.imageAttachments[self.selectedAttachmentIndex];
BITImageAnnotationViewController *annotationEditor = [[BITImageAnnotationViewController alloc ] init];
@@ -615,11 +658,22 @@
annotationEditor.image = attachment.imageRepresentation;
[self presentViewController:navController animated:YES completion:nil];
}
} else {
}
- (void)cancelAction {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[self.textView becomeFirstResponder];
}
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == [actionSheet destructiveButtonIndex]) {
[self deleteAction];
} else if (buttonIndex != [actionSheet cancelButtonIndex]) {
[self editAction];
} else {
[self cancelAction];
}
_actionSheetVisible = NO;
}

View File

@@ -287,6 +287,45 @@
}
- (void)deleteAllMessagesAction:(id)sender {
// requires iOS 8
id uialertcontrollerClass = NSClassFromString(@"UIAlertController");
if (uialertcontrollerClass) {
NSString *title = BITHockeyLocalizedString(@"HockeyFeedbackListButtonDeleteAllMessages");
NSString *message = BITHockeyLocalizedString(@"HockeyFeedbackListDeleteAllTitle");
UIAlertControllerStyle controllerStyle = UIAlertControllerStyleAlert;
if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) {
controllerStyle = UIAlertControllerStyleActionSheet;
title = BITHockeyLocalizedString(@"HockeyFeedbackListDeleteAllTitle");
message = nil;
}
__weak typeof(self) weakSelf = self;
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title
message:message
preferredStyle:controllerStyle];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"HockeyFeedbackListDeleteAllCancel")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {}];
[alertController addAction:cancelAction];
UIAlertAction* deleteAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"HockeyFeedbackListDeleteAllDelete")
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
[strongSelf deleteAllMessages];
}];
[alertController addAction:deleteAction];
[self presentViewController:alertController animated:YES completion:nil];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) {
UIActionSheet *deleteAction = [[UIActionSheet alloc] initWithTitle:BITHockeyLocalizedString(@"HockeyFeedbackListDeleteAllTitle")
delegate:self
@@ -307,6 +346,8 @@
[deleteAction setTag:0];
[deleteAction show];
}
#pragma clang diagnostic pop
}
}
- (UIView*) viewForShowingActionSheetOnPhone {
@@ -767,6 +808,47 @@
#pragma mark - BITAttributedLabelDelegate
- (void)attributedLabel:(BITAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url {
// requires iOS 8
id uialertcontrollerClass = NSClassFromString(@"UIAlertController");
if (uialertcontrollerClass) {
UIAlertControllerStyle controllerStyle = UIAlertControllerStyleAlert;
if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) {
controllerStyle = UIAlertControllerStyleActionSheet;
}
UIAlertController *linkAction = [UIAlertController alertControllerWithTitle:[url absoluteString]
message:nil
preferredStyle:controllerStyle];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"HockeyFeedbackListLinkActionCancel")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {}];
[linkAction addAction:cancelAction];
UIAlertAction* openAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"HockeyFeedbackListLinkActionOpen")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[url absoluteString]]];
}];
[linkAction addAction:openAction];
UIAlertAction* copyAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"HockeyFeedbackListLinkActionCopy")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.URL = [NSURL URLWithString:[url absoluteString]];
}];
[linkAction addAction:copyAction];
[self presentViewController:linkAction animated:YES completion:nil];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) {
UIActionSheet *linkAction = [[UIActionSheet alloc] initWithTitle:[url absoluteString]
delegate:self
@@ -788,11 +870,15 @@
[linkAction setTag:1];
[linkAction show];
}
#pragma clang diagnostic pop
}
}
#pragma mark - UIAlertViewDelegate
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == alertView.cancelButtonIndex) {
return;
@@ -811,7 +897,7 @@
}
}
}
#pragma clang diagnostic pop
#pragma mark - UIActionSheetDelegate

View File

@@ -1070,6 +1070,8 @@ NSString *const kBITFeedbackUpdateAttachmentThumbnail = @"BITFeedbackUpdateAttac
#pragma mark - UIAlertViewDelegate
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// invoke the selected action from the action sheet for a location element
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
@@ -1079,6 +1081,7 @@ NSString *const kBITFeedbackUpdateAttachmentThumbnail = @"BITFeedbackUpdateAttac
[self showFeedbackListView];
}
}
#pragma clang diagnostic pop
#pragma mark - Observation Handling

View File

@@ -97,7 +97,7 @@ typedef NS_ENUM(NSInteger, BITImageAnnotationViewControllerInteractionMode) {
self.imageView.image = self.image;
self.imageView.contentMode = UIViewContentModeScaleToFill;
self.view.frame = UIScreen.mainScreen.applicationFrame;
self.view.frame = UIScreen.mainScreen.bounds;
[self.view addSubview:self.imageView];
// Erm.
@@ -113,13 +113,8 @@ typedef NS_ENUM(NSInteger, BITImageAnnotationViewControllerInteractionMode) {
self.imageView.userInteractionEnabled = YES;
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_8_0
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc ] initWithImage:bit_imageNamed(@"Cancel.png", BITHOCKEYSDK_BUNDLE) landscapeImagePhone:bit_imageNamed(@"Cancel.png", BITHOCKEYSDK_BUNDLE) style:UIBarButtonItemStylePlain target:self action:@selector(discard:)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc ] initWithImage:bit_imageNamed(@"Ok.png", BITHOCKEYSDK_BUNDLE) landscapeImagePhone:bit_imageNamed(@"Ok.png", BITHOCKEYSDK_BUNDLE) style:UIBarButtonItemStylePlain target:self action:@selector(save:)];
#else
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc ] initWithImage:bit_imageNamed(@"Cancel.png", BITHOCKEYSDK_BUNDLE) landscapeImagePhone:bit_imageNamed(@"Cancel.png", BITHOCKEYSDK_BUNDLE) style:UIBarButtonItemStyleBordered target:self action:@selector(discard:)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc ] initWithImage:bit_imageNamed(@"Ok.png", BITHOCKEYSDK_BUNDLE) landscapeImagePhone:bit_imageNamed(@"Ok.png", BITHOCKEYSDK_BUNDLE) style:UIBarButtonItemStyleBordered target:self action:@selector(save:)];
#endif
self.view.autoresizesSubviews = NO;
}
@@ -364,7 +359,14 @@ typedef NS_ENUM(NSInteger, BITImageAnnotationViewControllerInteractionMode) {
self.navigationController.navigationBar.alpha = 1.0;
}
if ([self respondsToSelector:@selector(prefersStatusBarHidden)]) {
[self setNeedsStatusBarAppearanceUpdate];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[[UIApplication sharedApplication] setStatusBarHidden:NO];
#pragma clang diagnostic pop
}
} completion:^(BOOL finished) {
[self fitImageViewFrame];
@@ -379,7 +381,14 @@ typedef NS_ENUM(NSInteger, BITImageAnnotationViewControllerInteractionMode) {
self.navigationController.navigationBar.alpha = 0.0;
}
if ([self respondsToSelector:@selector(prefersStatusBarHidden)]) {
[self setNeedsStatusBarAppearanceUpdate];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[[UIApplication sharedApplication] setStatusBarHidden:YES];
#pragma clang diagnostic pop
}
} completion:^(BOOL finished) {
[self fitImageViewFrame];

View File

@@ -417,6 +417,47 @@
if (!_updateAlertShowing) {
NSString *versionString = [NSString stringWithFormat:@"%@ %@", BITHockeyLocalizedString(@"UpdateVersion"), _newStoreVersion];
// requires iOS 8
id uialertcontrollerClass = NSClassFromString(@"UIAlertController");
if (uialertcontrollerClass) {
__weak typeof(self) weakSelf = self;
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:BITHockeyLocalizedString(@"UpdateAvailable")
message:[NSString stringWithFormat:BITHockeyLocalizedString(@"UpdateAlertTextWithAppVersion"), versionString]
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ignoreAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"UpdateIgnore")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
[strongSelf ignoreAction];
}];
[alertController addAction:ignoreAction];
UIAlertAction *remindAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"UpdateRemindMe")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
[strongSelf remindAction];
}];
[alertController addAction:remindAction];
UIAlertAction *showAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"UpdateShow")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
[strongSelf showAction];
}];
[alertController addAction:showAction];
[self showView:alertController];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:BITHockeyLocalizedString(@"UpdateAvailable")
message:[NSString stringWithFormat:BITHockeyLocalizedString(@"UpdateAlertTextWithAppVersion"), versionString]
delegate:self
@@ -424,6 +465,9 @@
otherButtonTitles:BITHockeyLocalizedString(@"UpdateRemindMe"), BITHockeyLocalizedString(@"UpdateShow"), nil
];
[alertView show];
#pragma clang diagnostic pop
}
_updateAlertShowing = YES;
}
}
@@ -442,17 +486,18 @@
#pragma mark - UIAlertViewDelegate
// invoke the selected action from the action sheet for a location element
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
- (void)ignoreAction {
_updateAlertShowing = NO;
if (buttonIndex == [alertView cancelButtonIndex]) {
// Ignore
[self.userDefaults setObject:_newStoreVersion forKey:kBITStoreUpdateIgnoreVersion];
[self.userDefaults synchronize];
} else if (buttonIndex == [alertView firstOtherButtonIndex]) {
// Remind button
} else if (buttonIndex == [alertView firstOtherButtonIndex] + 1) {
// Show button
}
- (void)remindAction {
_updateAlertShowing = NO;
}
- (void)showAction {
_updateAlertShowing = NO;
[self.userDefaults setObject:_newStoreVersion forKey:kBITStoreUpdateIgnoreVersion];
[self.userDefaults synchronize];
@@ -462,7 +507,22 @@
BITHockeyLog(@"WARNING: The app store page couldn't be opened, since we did not get a valid URL from the store API.");
}
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// invoke the selected action from the action sheet for a location element
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == [alertView cancelButtonIndex]) {
[self ignoreAction];
} else if (buttonIndex == [alertView firstOtherButtonIndex]) {
// Remind button
[self remindAction];
} else if (buttonIndex == [alertView firstOtherButtonIndex] + 1) {
// Show button
[self showAction];
}
}
#pragma clang diagnostic pop
@end

View File

@@ -89,11 +89,32 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
// only show error if we enable that
if (_showFeedback) {
// requires iOS 8
id uialertcontrollerClass = NSClassFromString(@"UIAlertController");
if (uialertcontrollerClass) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:BITHockeyLocalizedString(@"UpdateError")
message:[error localizedDescription]
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"HockeyOK")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[alertController addAction:okAction];
[self showView:alertController];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:BITHockeyLocalizedString(@"UpdateError")
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:BITHockeyLocalizedString(@"OK") otherButtonTitles:nil];
cancelButtonTitle:BITHockeyLocalizedString(@"HockeyOK")
otherButtonTitles:nil];
[alert show];
#pragma clang diagnostic pop
}
_showFeedback = NO;
}
}
@@ -520,19 +541,111 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
if ([self isUpdateManagerDisabled]) return;
if (!_updateAlertShowing) {
NSString *title = BITHockeyLocalizedString(@"UpdateAvailable");
NSString *message = [NSString stringWithFormat:BITHockeyLocalizedString(@"UpdateAlertMandatoryTextWithAppVersion"), [self.newestAppVersion nameAndVersionString]];
if ([self hasNewerMandatoryVersion]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:BITHockeyLocalizedString(@"UpdateAvailable")
message:[NSString stringWithFormat:BITHockeyLocalizedString(@"UpdateAlertMandatoryTextWithAppVersion"), [self.newestAppVersion nameAndVersionString]]
// requires iOS 8
id uialertcontrollerClass = NSClassFromString(@"UIAlertController");
if (uialertcontrollerClass) {
__weak typeof(self) weakSelf = self;
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *showAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"UpdateShow")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
_updateAlertShowing = NO;
if (strongSelf.blockingView) {
[strongSelf.blockingView removeFromSuperview];
}
[strongSelf showUpdateView];
}];
[alertController addAction:showAction];
UIAlertAction *installAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"UpdateInstall")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
_updateAlertShowing = NO;
(void)[strongSelf initiateAppDownload];
}];
[alertController addAction:installAction];
[self showView:alertController];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:nil
otherButtonTitles:BITHockeyLocalizedString(@"UpdateShow"), BITHockeyLocalizedString(@"UpdateInstall"), nil
];
[alertView setTag:BITUpdateAlertViewTagMandatoryUpdate];
[alertView show];
#pragma clang diagnostic pop
}
_updateAlertShowing = YES;
} else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:BITHockeyLocalizedString(@"UpdateAvailable")
message:[NSString stringWithFormat:BITHockeyLocalizedString(@"UpdateAlertTextWithAppVersion"), [self.newestAppVersion nameAndVersionString]]
message = [NSString stringWithFormat:BITHockeyLocalizedString(@"UpdateAlertTextWithAppVersion"), [self.newestAppVersion nameAndVersionString]];
// requires iOS 8
id uialertcontrollerClass = NSClassFromString(@"UIAlertController");
if (uialertcontrollerClass) {
__weak typeof(self) weakSelf = self;
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ignoreAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"UpdateIgnore")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
_updateAlertShowing = NO;
if ([strongSelf expiryDateReached] && !strongSelf.blockingView) {
[strongSelf alertFallback:_blockingScreenMessage];
}
}];
[alertController addAction:ignoreAction];
UIAlertAction *showAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"UpdateShow")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
_updateAlertShowing = NO;
if (strongSelf.blockingView) {
[strongSelf.blockingView removeFromSuperview];
}
[strongSelf showUpdateView];
}];
[alertController addAction:showAction];
if (self.isShowingDirectInstallOption) {
UIAlertAction *installAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"UpdateInstall")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
_updateAlertShowing = NO;
(void)[strongSelf initiateAppDownload];
}];
[alertController addAction:installAction];
}
[self showView:alertController];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:BITHockeyLocalizedString(@"UpdateIgnore")
otherButtonTitles:BITHockeyLocalizedString(@"UpdateShow"), nil
@@ -542,6 +655,8 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
}
[alertView setTag:BITUpdateAlertViewTagDefaultUpdate];
[alertView show];
#pragma clang diagnostic pop
}
_updateAlertShowing = YES;
}
}
@@ -615,6 +730,39 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
// nag the user with neverending alerts if we cannot find out the window for presenting the covering sheet
- (void)alertFallback:(NSString *)message {
// requires iOS 8
id uialertcontrollerClass = NSClassFromString(@"UIAlertController");
if (uialertcontrollerClass) {
__weak typeof(self) weakSelf = self;
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"HockeyOK")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
[strongSelf alertFallback:_blockingScreenMessage];
}];
[alertController addAction:okAction];
if (!self.disableUpdateCheckOptionWhenExpired && [message isEqualToString:_blockingScreenMessage]) {
UIAlertAction *checkAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"UpdateButtonCheck")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
[strongSelf checkForUpdateForExpiredVersion];
}];
[alertController addAction:checkAction];
}
[self showView:alertController];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil
message:message
delegate:self
@@ -629,6 +777,7 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
[alertView setTag:BITUpdateAlertViewTagNeverEndingAlertView];
[alertView show];
}
}
#pragma mark - RequestComments
@@ -741,8 +890,31 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
}
#if TARGET_IPHONE_SIMULATOR
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:BITHockeyLocalizedString(@"UpdateWarning") message:BITHockeyLocalizedString(@"UpdateSimulatorMessage") delegate:nil cancelButtonTitle:BITHockeyLocalizedString(@"HockeyOK") otherButtonTitles:nil];
// requires iOS 8
id uialertcontrollerClass = NSClassFromString(@"UIAlertController");
if (uialertcontrollerClass) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:BITHockeyLocalizedString(@"UpdateWarning")
message:BITHockeyLocalizedString(@"UpdateSimulatorMessage")
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"HockeyOK")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[alertController addAction:okAction];
[self showView:alertController];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:BITHockeyLocalizedString(@"UpdateWarning")
message:BITHockeyLocalizedString(@"UpdateSimulatorMessage")
delegate:nil
cancelButtonTitle:BITHockeyLocalizedString(@"HockeyOK")
otherButtonTitles:nil];
[alert show];
#pragma clang diagnostic pop
}
return NO;
#else
@@ -921,12 +1093,40 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
versionString = [shortVersionString length] ? [NSString stringWithFormat:@"(%@)", versionString] : versionString;
NSString *currentVersionString = [NSString stringWithFormat:@"%@ %@ %@%@", self.newestAppVersion.name, BITHockeyLocalizedString(@"UpdateVersion"), shortVersionString, versionString];
NSString *alertMsg = [NSString stringWithFormat:BITHockeyLocalizedString(@"UpdateNoUpdateAvailableMessage"), currentVersionString];
// requires iOS 8
id uialertcontrollerClass = NSClassFromString(@"UIAlertController");
if (uialertcontrollerClass) {
__weak typeof(self) weakSelf = self;
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:BITHockeyLocalizedString(@"UpdateNoUpdateAvailableTitle")
message:alertMsg
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:BITHockeyLocalizedString(@"HockeyOK")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
typeof(self) strongSelf = weakSelf;
_updateAlertShowing = NO;
if ([strongSelf expiryDateReached] && !strongSelf.blockingView) {
[strongSelf alertFallback:_blockingScreenMessage];
}
}];
[alertController addAction:okAction];
[self showView:alertController];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:BITHockeyLocalizedString(@"UpdateNoUpdateAvailableTitle")
message:alertMsg
delegate:nil
cancelButtonTitle:BITHockeyLocalizedString(@"HockeyOK")
otherButtonTitles:nil];
[alert show];
#pragma clang diagnostic pop
}
}
if (self.isUpdateAvailable && (self.alwaysShowUpdateReminder || newVersionDiffersFromCachedVersion || [self hasNewerMandatoryVersion])) {
@@ -1049,6 +1249,8 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
#pragma mark - UIAlertViewDelegate
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// invoke the selected action from the action sheet for a location element
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if ([alertView tag] == BITUpdateAlertViewTagNeverEndingAlertView) {
@@ -1076,6 +1278,7 @@ typedef NS_ENUM(NSInteger, BITUpdateAlertViewTag) {
}
}
}
#pragma clang diagnostic pop
@end