-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Wenzhi
committed
Jun 16, 2017
1 parent
384b155
commit 200eb47
Showing
59 changed files
with
586 additions
and
615 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
#import "ABKModalWebViewController.h" | ||
#import "ABKNoConnectionLocalization.h" | ||
|
||
static NSString *const titleKeyPath = @"title"; | ||
static NSString *const estimatedProgressKeyPath = @"estimatedProgress"; | ||
static NSString *const localizedNoConnectionKey = @"Appboy.no-connection.message"; | ||
|
||
@implementation ABKModalWebViewController | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
|
||
UIViewController *webViewController = [[UIViewController alloc] init]; | ||
webViewController.edgesForExtendedLayout = UIRectEdgeNone; | ||
|
||
self.webView = [self getWebView]; | ||
webViewController.view = self.webView; | ||
|
||
[self setupProgressBarWithViewController:webViewController]; | ||
|
||
UIBarButtonItem *closeBarButton = [self getDoneBarButtonItem]; | ||
[webViewController.navigationItem setRightBarButtonItem:closeBarButton]; | ||
|
||
[self.webView addObserver:self forKeyPath:titleKeyPath options:NSKeyValueObservingOptionNew context:nil]; | ||
[self.webView addObserver:self forKeyPath:estimatedProgressKeyPath options:NSKeyValueObservingOptionNew context:nil]; | ||
|
||
[self setViewControllers:@[webViewController]]; | ||
|
||
[self.webView loadRequest:[NSURLRequest requestWithURL:self.url]]; | ||
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES; | ||
} | ||
|
||
- (void)observeValueForKeyPath:(NSString *)keyPath | ||
ofObject:(id)object | ||
change:(NSDictionary<NSKeyValueChangeKey,id> *)change | ||
context:(void *)context { | ||
if ([titleKeyPath isEqualToString:keyPath]) { | ||
self.title = self.webView.title; | ||
} else if ([estimatedProgressKeyPath isEqualToString:keyPath]) { | ||
if (self.webView.estimatedProgress == 1.0) { | ||
[UIView animateWithDuration:1 animations:^{ | ||
self.progressBar.alpha = 0.0; | ||
}]; | ||
} else if (self.webView.estimatedProgress < 1.0) { | ||
self.progressBar.alpha = 1.0; | ||
[self.progressBar setProgress:self.webView.estimatedProgress animated:YES]; | ||
} | ||
} | ||
} | ||
|
||
- (void)dealloc { | ||
[self.webView removeObserver:self forKeyPath:titleKeyPath]; | ||
[self.webView removeObserver:self forKeyPath:estimatedProgressKeyPath]; | ||
} | ||
|
||
#pragma mark - Customization Methods | ||
|
||
/*! | ||
* @discussion Returns a WKWebView object, whose navigationDelegate is this ABKModalWebViewController instance. | ||
* | ||
* If you want to do any customization to the WKWebView, please override this method in an ABKModalWebViewController | ||
* category and return the customized WKWebView. All instances of ABKModalWebViewController will then | ||
* call the category's `getWebView` implementation instead of this method. | ||
* | ||
*/ | ||
- (WKWebView *)getWebView { | ||
WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectZero]; | ||
webView.navigationDelegate = self; | ||
return webView; | ||
} | ||
|
||
/*! | ||
* | ||
* @param viewController The view controller to which the progress bar will be added as a subview. | ||
* | ||
* @discussion Creates a UIProgressView and puts it on top of the param viewController. | ||
* | ||
* If you want to do any customization to the progress bar, please override this method in an ABKModalWebViewController | ||
* category and set up the progress bar. All instances of ABKModalWebViewController will then | ||
* call the category's `setupProgressBarWithViewController:` implementation instead of this method. | ||
* | ||
*/ | ||
- (void)setupProgressBarWithViewController:(UIViewController *)viewController { | ||
UIProgressView *progressBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar]; | ||
progressBar.alpha = 0; | ||
self.progressBar = progressBar; | ||
|
||
[viewController.view addSubview:self.progressBar]; | ||
self.progressBar.translatesAutoresizingMaskIntoConstraints = NO; | ||
[viewController.view addConstraint:[NSLayoutConstraint constraintWithItem:self.progressBar | ||
attribute:NSLayoutAttributeTop | ||
relatedBy:NSLayoutRelationEqual | ||
toItem:viewController.topLayoutGuide | ||
attribute:NSLayoutAttributeBottom | ||
multiplier:1.0 | ||
constant:0.0]]; | ||
[viewController.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[progressBar]|" | ||
options:NSLayoutFormatDirectionLeadingToTrailing | ||
metrics:nil | ||
views:@{@"progressBar" : self.progressBar}]]; | ||
} | ||
|
||
/*! | ||
* @discussion Returns the Done UIBarButtonItem, which allows the user to dismiss the modal web view. | ||
* | ||
* If you want to do any customization to the Done button, please override this method in an ABKModalWebViewController | ||
* category and return the customized UIBarButtonItem. All instances of ABKModalWebViewController will then | ||
* call the category's `getDoneBarButtonItem` implementation instead of this method. | ||
* | ||
*/ | ||
- (UIBarButtonItem *)getDoneBarButtonItem { | ||
return [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone | ||
target:self | ||
action:@selector(closeButtonPressed:)]; | ||
} | ||
|
||
- (void)closeButtonPressed:(id)sender { | ||
[self dismissViewControllerAnimated:YES completion:nil]; | ||
} | ||
|
||
#pragma mark - WKNavigationDelegate methods | ||
|
||
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction | ||
decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { | ||
NSString *URLString = [[navigationAction.request.mainDocumentURL absoluteString] lowercaseString]; | ||
NSArray *stringComponents = [URLString componentsSeparatedByString:@":"]; | ||
if ([stringComponents[1] hasPrefix:@"//itunes.apple.com"] || | ||
(![stringComponents[0] isEqual:@"http"] && | ||
![stringComponents[0] isEqual:@"https"])) { | ||
// Dismiss the modal web view and let the system handle the deep links | ||
if ([[UIApplication sharedApplication] openURL:navigationAction.request.URL]) { | ||
decisionHandler(WKNavigationActionPolicyCancel); | ||
[self dismissViewControllerAnimated:YES completion:nil]; | ||
} | ||
} | ||
decisionHandler(WKNavigationActionPolicyAllow); | ||
} | ||
|
||
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{ | ||
self.progressBar.alpha = 0.0; | ||
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO; | ||
} | ||
|
||
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation | ||
withError:(NSError *)error{ | ||
self.progressBar.alpha = 0.0; | ||
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO; | ||
|
||
// Display localized "No Connection" message | ||
UILabel *label = [[UILabel alloc] init]; | ||
label.textAlignment = NSTextAlignmentCenter; | ||
label.numberOfLines = 0; | ||
NSString *localizedNoConectionMessage = NSLocalizedString(@"Appboy.no-connection.message", @"No connection error message for URL loading failure"); | ||
if (localizedNoConectionMessage.length == 0 || [localizedNoConnectionKey isEqualToString:localizedNoConectionMessage]) { | ||
localizedNoConectionMessage = [ABKNoConnectionLocalization getNoConnectionLocalizedString]; | ||
} | ||
label.text = localizedNoConectionMessage; | ||
[self.webView addSubview:label]; | ||
label.translatesAutoresizingMaskIntoConstraints = NO; | ||
[self.webView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[noConnectionLabel]-10-|" | ||
options:NSLayoutFormatDirectionLeadingToTrailing | ||
metrics:nil | ||
views:@{@"noConnectionLabel" : label}]]; | ||
[self.webView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[noConnectionLabel]|" | ||
options:NSLayoutFormatAlignAllCenterY | ||
metrics:nil | ||
views:@{@"noConnectionLabel" : label}]]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#import "ABKNoConnectionLocalization.h" | ||
|
||
@implementation ABKNoConnectionLocalization | ||
|
||
+ (NSDictionary *)localizedNoConnectionStringDictionary { | ||
return @{@"ar":@"لا يمكن إجراء الاتصال بالشبكة. يرجى تكرار المحاولة لاحقا.", | ||
@"da":@"Kan ikke etablere netværksforbindelse. Prøv venligst senere.", | ||
@"de":@"Netzwerkverbindung kann nicht aufgebaut werden. Bitte später noch einmal versuchen.", | ||
@"en":@"Cannot establish network connection. Please try again later.", | ||
@"es-419":@"No se puede establecer conexión con la red. Por favor, vuelva a intentarlo más tarde.", | ||
@"es-MX":@"No se puede establecer conexión con la red. Por favor, vuelva a intentarlo más tarde.", | ||
@"es":@"No se puede establecer conexión de red. Por favor inténtelo más tarde.", | ||
@"et":@"Võrguühenduse loomine ebaõnnestus. Palun proovige hiljem uuesti.", | ||
@"fi":@"Verkkoyhteyttä ei voida luoda. Yritä myöhemmin uudelleen.", | ||
@"fil":@"Hindi makapagtatag ng koneksyon sa network. angyaring subukan muli mamaya.", | ||
@"fr":@"Impossible d'établir la connexion réseau. Veuillez réessayer ultérieurement.", | ||
@"he":@".לא ניתן לקבוע חיבור רשת.בבקשה נסה שוב בקרוב", | ||
@"hi":@"नेटवर्क कनेक्शन स्थापित नहीं हो रहा है।. कृपया बाद में दोबारा प्रयास करें।.", | ||
@"id":@"Tidak bisa melakukan koneksi jaringan. Coba lagi nanti.", | ||
@"it":@"Impossibile stabilire una connessione di rete. Riprovare più tardi.", | ||
@"ja":@"ネットワークに接続できません。後でもう一度試してください。", | ||
@"km":@"មិនអាចបង្កើតបណ្តាញតភ្ជាប់បានទេ. សូមព្យាយាមម្តងទៀតនៅពេលក្រោយ.", | ||
@"ko":@"네트워크 연결을 할 수 없습니다. 나중에 다시 시도해 주십시오.", | ||
@"lo":@"ບໍ່ສາມາດຕັ້ງການເຊື່ອມຕໍ່ເຄືອຂ່າຍໄດ້. ກະລຸນາລອງໃໝ່ພາຍຫຼັງ.", | ||
@"ms":@"Tidak boleh membuat sambungan rangkaian. Sila cuba kemudian.", | ||
@"my":@"ကြန္ယက္ဆက္သြယ္ျခင္း မျပဳလုပ္ႏိုင္ပါ။. ေက်းဇူးျပဳ၍ ထပ္မံၾကိဳးစားၾကည္႕ပါ။.", | ||
@"nb":@"Kan ikke etablere nettverkstilkobling. Vennligst prøv igjen senere.", | ||
@"nl":@"Kan geen netwerkverbinding maken. Probeer het later opnieuw.", | ||
@"pl":@"Nie można ustanowić połączenia z siecią. Proszę spróbować ponownie później.", | ||
@"pt-PT":@"Não é possível estabelecer a ligação à rede. Por favor, tente mais tarde.", | ||
@"pt":@"Não é possível estabelecer uma conexão de rede. Tente novamente mais tarde.", | ||
@"ru":@"Невозможно установить сетевое подключение. Пожалуйста, повторите попытку позже.", | ||
@"sv":@"Det gick inte att skapa en nätverksanslutning. Försök igen senare.", | ||
@"th":@"ไม่สามารถสร้างการเชื่อมต่อเครือข่าย. กรุณาลองใหม่ภายหลัง.", | ||
@"vi":@"Không thể thiết lập kết nối mạng. Vui lòng thử lại sau.", | ||
@"zh-Hans":@"无法建立网络连接。请稍候再试。", | ||
@"zh-Hant":@"無法建立網路連線。請稍候再試。", | ||
@"zh-HK":@"無法建立網路連線。請稍候再試。", | ||
@"zh-TW":@"無法建立網路連線。請稍候再試。", | ||
@"zh":@"无法建立网络连接。请稍候再试。"}; | ||
} | ||
|
||
+ (NSString *)getNoConnectionLocalizedString { | ||
NSString *language = [[NSLocale preferredLanguages] count]? [NSLocale preferredLanguages][0]: @"en"; | ||
NSDictionary *localizedStringDict = [self localizedNoConnectionStringDictionary]; | ||
|
||
while (localizedStringDict[language] == nil && [language rangeOfString:@"-"].location != NSNotFound) { | ||
NSArray *languageComponent = [language componentsSeparatedByString:@"-"]; | ||
language = [[languageComponent subarrayWithRange:NSMakeRange(0, languageComponent.count - 1)] componentsJoinedByString:@"-"]; | ||
} | ||
NSString *localizedString = localizedStringDict[language] ? localizedStringDict[language] : localizedStringDict[@"en"]; | ||
return localizedString; | ||
} | ||
|
||
@end |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+2 Bytes
(100%)
AppboyKit/Appboy.bundle/ABKInAppMessageFullViewController.nib/objects.nib
Binary file not shown.
Binary file modified
BIN
-2 Bytes
(100%)
AppboyKit/Appboy.bundle/ABKInAppMessageFullViewController.nib/runtime.nib
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
AppboyKit/Appboy.bundle/ABKInAppMessageHTMLFullViewController.nib
Binary file not shown.
Binary file modified
BIN
-4 Bytes
(100%)
AppboyKit/Appboy.bundle/ABKInAppMessageModalViewController.nib/objects.nib
Binary file not shown.
Binary file modified
BIN
+6 Bytes
(100%)
AppboyKit/Appboy.bundle/ABKInAppMessageModalViewController.nib/runtime.nib
Binary file not shown.
Binary file modified
BIN
+6 Bytes
(100%)
AppboyKit/Appboy.bundle/ABKInAppMessageSlideupViewController.nib/objects.nib
Binary file not shown.
Binary file modified
BIN
-2 Bytes
(100%)
AppboyKit/Appboy.bundle/ABKInAppMessageSlideupViewController.nib/runtime.nib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 8 additions & 0 deletions
8
AppboyKit/headers/AppboyKitLibrary/ABKInAppMessageWindowController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
#import <UIKit/UIKit.h> | ||
|
||
|
||
/*! | ||
* Appboy Public API: ABKInAppMessageWindowController | ||
* | ||
* ABKInAppMessageWindowController is the view controller responsible for housing and displaying | ||
* ABKInAppMessageViewControllers and performing actions after the in-app message is clicked. Instances | ||
* of ABKInAppMessageWindowController are deallocated after the in-app message is dismissed. | ||
*/ | ||
@interface ABKInAppMessageWindowController : UIViewController <UIGestureRecognizerDelegate> | ||
|
||
@end |
23 changes: 23 additions & 0 deletions
23
AppboyKit/headers/AppboyKitLibrary/ABKModalWebViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#import <UIKit/UIKit.h> | ||
#import <WebKit/WebKit.h> | ||
|
||
@interface ABKModalWebViewController : UINavigationController <WKNavigationDelegate> | ||
|
||
/*! | ||
* The url the modal web view controller should open. Please note that this is the initial url and | ||
* won't be updated if the initial url re-directs to another url. | ||
*/ | ||
@property NSURL *url; | ||
|
||
/*! | ||
* The WKWebView which displays the web view. | ||
*/ | ||
@property (nonatomic) IBOutlet WKWebView *webView; | ||
|
||
/*! | ||
* The UIProgressView which shows the web view loading process. It will be on top of the web view and | ||
* will disappear as soon as the page is loaded. | ||
*/ | ||
@property (nonatomic) IBOutlet UIProgressView *progressBar; | ||
|
||
@end |
7 changes: 7 additions & 0 deletions
7
AppboyKit/headers/AppboyKitLibrary/ABKNoConnectionLocalization.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
@interface ABKNoConnectionLocalization : NSObject | ||
|
||
+ (NSString *)getNoConnectionLocalizedString; | ||
|
||
@end |
Oops, something went wrong.