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

Revert "CB-14045 - reinit url after app freezes on 4.5.x", on 4.5.x only #484

Merged
merged 1 commit into from
Dec 20, 2018
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
24 changes: 0 additions & 24 deletions CordovaLib/Classes/Public/CDVViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -720,33 +720,12 @@ - (void)onAppWillTerminate:(NSNotification*)notification
}
}

- (bool)isUrlEmpty:(NSURL *)url
{
if (!url || (url == (id) [NSNull null])) {
return true;
}
NSString *urlAsString = [url absoluteString];
return (urlAsString == (id) [NSNull null] || [urlAsString length]==0 || [urlAsString isEqualToString:@"about:blank"]);
}

- (bool)checkAndReinitViewUrl
{
NSURL* appURL = [self appUrl];
if ([self isUrlEmpty: [self.webViewEngine URL]] && ![self isUrlEmpty: appURL]) {
NSURLRequest* appReq = [NSURLRequest requestWithURL:appURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
[self.webViewEngine loadRequest:appReq];
return true;
}
return false;
}

/*
This method is called to let your application know that it is about to move from the active to inactive state.
You should use this method to pause ongoing tasks, disable timer, ...
*/
- (void)onAppWillResignActive:(NSNotification*)notification
{
[self checkAndReinitViewUrl];
// NSLog(@"%@",@"applicationWillResignActive");
[self.commandDelegate evalJs:@"cordova.fireDocumentEvent('resign');" scheduledOnRunLoop:NO];
}
Expand All @@ -758,7 +737,6 @@ - (void)onAppWillResignActive:(NSNotification*)notification
*/
- (void)onAppWillEnterForeground:(NSNotification*)notification
{
[self checkAndReinitViewUrl];
// NSLog(@"%@",@"applicationWillEnterForeground");
[self.commandDelegate evalJs:@"cordova.fireDocumentEvent('resume');"];

Expand All @@ -773,7 +751,6 @@ - (void)onAppWillEnterForeground:(NSNotification*)notification
// This method is called to let your application know that it moved from the inactive to active state.
- (void)onAppDidBecomeActive:(NSNotification*)notification
{
[self checkAndReinitViewUrl];
// NSLog(@"%@",@"applicationDidBecomeActive");
[self.commandDelegate evalJs:@"cordova.fireDocumentEvent('active');"];
}
Expand All @@ -784,7 +761,6 @@ - (void)onAppDidBecomeActive:(NSNotification*)notification
*/
- (void)onAppDidEnterBackground:(NSNotification*)notification
{
[self checkAndReinitViewUrl];
// NSLog(@"%@",@"applicationDidEnterBackground");
[self.commandDelegate evalJs:@"cordova.fireDocumentEvent('pause', null, true);" scheduledOnRunLoop:NO];
}
Expand Down
30 changes: 0 additions & 30 deletions tests/CordovaLibTests/CDVViewControllerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ @interface CDVViewControllerTest : XCTestCase

@end

@interface CDVViewController ()

// expose private interface
- (bool)checkAndReinitViewUrl;
- (bool)isUrlEmpty:(NSURL*)url;

@end

@implementation CDVViewControllerTest

-(CDVViewController*)viewController{
Expand Down Expand Up @@ -97,27 +89,5 @@ -(void)testColorFromColorString{
XCTAssertNil([viewController colorFromColorString:@"#NOTHEX"]);
}

-(void)testIsUrlEmpty{
CDVViewController* viewController = [self viewController];
XCTAssertTrue([viewController isUrlEmpty:(id)[NSNull null]]);
XCTAssertTrue([viewController isUrlEmpty:nil]);
XCTAssertTrue([viewController isUrlEmpty:[NSURL URLWithString:@""]]);
XCTAssertTrue([viewController isUrlEmpty:[NSURL URLWithString:@"about:blank"]]);
}

-(void)testIfItLoadsAppUrlIfCurrentViewIsBlank{
CDVViewController* viewController = [self viewController];

NSString* appUrl = @"about:blank";
NSString* html = @"<html><body></body></html>";
[viewController.webViewEngine loadHTMLString:html baseURL:[NSURL URLWithString:appUrl]];
XCTAssertFalse([viewController checkAndReinitViewUrl]);

appUrl = @"https://cordova.apache.org";
viewController.startPage = appUrl;
[viewController.webViewEngine loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:appUrl]]];
XCTAssertTrue([viewController checkAndReinitViewUrl]);
}

@end