[ 
https://issues.apache.org/jira/browse/CB-14045?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16476868#comment-16476868
 ] 

ASF GitHub Bot commented on CB-14045:
-------------------------------------

shazron closed pull request #363: CB-14045 - reinit url after app freezes
URL: https://github.com/apache/cordova-ios/pull/363
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/CordovaLib/Classes/Public/CDVViewController.m 
b/CordovaLib/Classes/Public/CDVViewController.m
index d0c05865a..13f1a9038 100644
--- a/CordovaLib/Classes/Public/CDVViewController.m
+++ b/CordovaLib/Classes/Public/CDVViewController.m
@@ -720,12 +720,33 @@ - (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];
 }
@@ -737,6 +758,7 @@ - (void)onAppWillResignActive:(NSNotification*)notification
  */
 - (void)onAppWillEnterForeground:(NSNotification*)notification
 {
+    [self checkAndReinitViewUrl];
     // NSLog(@"%@",@"applicationWillEnterForeground");
     [self.commandDelegate evalJs:@"cordova.fireDocumentEvent('resume');"];
 
@@ -751,6 +773,7 @@ - 
(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');"];
 }
@@ -761,6 +784,7 @@ - (void)onAppDidBecomeActive:(NSNotification*)notification
  */
 - (void)onAppDidEnterBackground:(NSNotification*)notification
 {
+    [self checkAndReinitViewUrl];
     // NSLog(@"%@",@"applicationDidEnterBackground");
     [self.commandDelegate evalJs:@"cordova.fireDocumentEvent('pause', null, 
true);" scheduledOnRunLoop:NO];
 }
diff --git a/tests/CordovaLibTests/CDVViewControllerTest.m 
b/tests/CordovaLibTests/CDVViewControllerTest.m
index 9d0f7c06f..9e13a883f 100644
--- a/tests/CordovaLibTests/CDVViewControllerTest.m
+++ b/tests/CordovaLibTests/CDVViewControllerTest.m
@@ -26,6 +26,14 @@ @interface CDVViewControllerTest : XCTestCase
 
 @end
 
+@interface CDVViewController ()
+
+// expose private interface
+- (bool)checkAndReinitViewUrl;
+- (bool)isUrlEmpty:(NSURL*)url;
+
+@end
+
 @implementation CDVViewControllerTest
 
 -(CDVViewController*)viewController{
@@ -89,5 +97,27 @@ -(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
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> iOS 11.3 - app freeze/sleep
> ---------------------------
>
>                 Key: CB-14045
>                 URL: https://issues.apache.org/jira/browse/CB-14045
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: cordova-ios
>    Affects Versions: cordova@7.1.0, cordova-ios@4.5.4
>            Reporter: Robert
>            Assignee: Suraj Pindoria
>            Priority: Blocker
>              Labels: ios, ios11, lock, performance, sleep
>
> Users with iOS 11.3 can’t use the app when device is locked for more than 10 
> minutes.
> Event onResume not firing.
> Steps to Reproduce: 
> Install Fitatu app. 
> Open app on any view. 
> Lock the device for more than 10 minutes. 
> After 10 minutes, unlock device.
> Expected Results: 
> App wakes up and the UI is responding (e.g. user is able to click buttons)
> Actual Results: 
> App wakes up and the UI is blocked (user is not able to click buttons)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org
For additional commands, e-mail: issues-h...@cordova.apache.org

Reply via email to