Topic
  • 4 replies
  • Latest Post - ‏2013-01-08T19:18:32Z by SystemAdmin
SystemAdmin
SystemAdmin
2327 Posts

Pinned topic Nil view controller in application:didFinishLaunchingWithOptions (WL5.0.5)

‏2013-01-08T18:14:33Z |
Starting with a clean WL 5.0.5 project the CDVViewController is nil when overriding application:didFinishLaunchingWithOptions:

Is this a known bug? If so is there any workaround?
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Nil view controller in application:didFinishLaunchingWithOptions (WL5.0.5)

    ‏2013-01-08T18:40:47Z  
    Hello,

    This was working on 5003. Is there a different way this should be accomplished with the later Cordova version? Or perhaps its a regression?

    Aaron Allsbrook
    ClearBlade Mobile Lead
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Nil view controller in application:didFinishLaunchingWithOptions (WL5.0.5)

    ‏2013-01-08T19:03:40Z  
    Thanks for the response, but I'm not sure this is the sort of thing I can move forward with based on how we are doing our first release. I will open a PMR.

    Thanks.
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Nil view controller in application:didFinishLaunchingWithOptions (WL5.0.5)

    ‏2013-01-08T19:17:25Z  
    Yes, this is a known problem and breaks remote loading in 5.0.5. I am looking to see if the APAR on it was published, in the meantime you should be able to use the following workaround:

    Polling on the webView to see when it is not nil anymore, on that moment loads the remote URL:
    
    
    //Additional method used to determine URL for remote loading - (NSString*) getRemoteURL
    { NSString* plistLoc =[[NSBundle mainBundle]pathForResource:@
    "worklight" ofType:@
    "plist"]; 
    
    if(plistLoc == nil)
    { [NSException raise:@
    "[Remote Load Initialization Error]" format:@
    "Unable to locate worklight.plist"]; 
    } NSDictionary* wlProps = [NSDictionary dictionaryWithContentsOfFile:plistLoc]; NSString* proto = [wlProps valueForKey:@
    "protocol"]; NSString* host = [wlProps valueForKey:@
    "host"]; NSString* port = [wlProps valueForKey:@
    "port"]; 
    //Ensure all required keys are in the plist 
    
    if(proto == nil || host == nil || port == nil)
    { [NSException raise:@
    "[Remote Load Initialization Error]" format:@
    "host, port and protocol are all required keys in worklight.plist"]; 
    } NSString* baseURL = [NSString stringWithFormat:@
    "%@://%@:%@%@", proto, host, port, @
    "/conference"]; 
    
    return baseURL; 
    }   -(
    
    void) loadRemoteURL
    { 
    
    if (![self viewController]) 
    { [self performSelector:@selector(loadRemoteURL) withObject:nil afterDelay:0.02]; 
    } 
    
    else 
    { NSURL* remoteURL = [NSURL URLWithString:[self getRemoteURL]]; NSURLRequest* request = [NSURLRequest requestWithURL:remoteURL]; [self.viewController.webView loadRequest:request]; 
    } 
    }   
    //Used to remotely load starting page -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
    { BOOL superResult = [
    
    super application:application didFinishLaunchingWithOptions:launchOptions]; [self loadRemoteURL]; 
    
    return superResult; 
    }
    
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Nil view controller in application:didFinishLaunchingWithOptions (WL5.0.5)

    ‏2013-01-08T19:18:32Z  
    Yes, this is a known problem and breaks remote loading in 5.0.5. I am looking to see if the APAR on it was published, in the meantime you should be able to use the following workaround:

    Polling on the webView to see when it is not nil anymore, on that moment loads the remote URL:
    <pre class="jive-pre"> //Additional method used to determine URL for remote loading - (NSString*) getRemoteURL { NSString* plistLoc =[[NSBundle mainBundle]pathForResource:@ "worklight" ofType:@ "plist"]; if(plistLoc == nil) { [NSException raise:@ "[Remote Load Initialization Error]" format:@ "Unable to locate worklight.plist"]; } NSDictionary* wlProps = [NSDictionary dictionaryWithContentsOfFile:plistLoc]; NSString* proto = [wlProps valueForKey:@ "protocol"]; NSString* host = [wlProps valueForKey:@ "host"]; NSString* port = [wlProps valueForKey:@ "port"]; //Ensure all required keys are in the plist if(proto == nil || host == nil || port == nil) { [NSException raise:@ "[Remote Load Initialization Error]" format:@ "host, port and protocol are all required keys in worklight.plist"]; } NSString* baseURL = [NSString stringWithFormat:@ "%@://%@:%@%@", proto, host, port, @ "/conference"]; return baseURL; } -( void) loadRemoteURL { if (![self viewController]) { [self performSelector:@selector(loadRemoteURL) withObject:nil afterDelay:0.02]; } else { NSURL* remoteURL = [NSURL URLWithString:[self getRemoteURL]]; NSURLRequest* request = [NSURLRequest requestWithURL:remoteURL]; [self.viewController.webView loadRequest:request]; } } //Used to remotely load starting page -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { BOOL superResult = [ super application:application didFinishLaunchingWithOptions:launchOptions]; [self loadRemoteURL]; return superResult; } </pre>
    Haven't quite got the forum formatting correct - the lines that appear as strike-thru are actually enclosed in square brackets.

    Edit (IdanAdar): fixed code snippet quote above.