breautek commented on issue #723:
URL: https://github.com/apache/cordova-ios/issues/723#issuecomment-751407768


   > As far as I know, the only way to ensure it is by adding a setTimeout(..., 
0) to make sure that the handleOpenURL that is called in the objective-c code 
is not executed before the deviceready that the cordova developer wirtes.
   
   The objective-c code uses `deviceready`:
   
   ```javascript
   document.addEventListener('deviceready', function() {
       if (typeof handleOpenURL === 'function') {
           handleOpenURL(\"%@\");
       }
   });
   ```
   
   Where `%@` is a native string placeholder to be replaced with another value.
   
   So `handleOpenURL` will never be called before `deviceready` because it's 
inside the `deviceready` event. But you do still need to make sure 
`handleOpenURL` is defined before this occurs.
   
   So using my both example where you may have something like this in your html:
   
   ```html
   <script src="cordova.js"></script>
   <script src="myapp.js"></script>
   ```
   
   And if you have `myapp.js`: :heavy_check_mark: 
   ```javascript
   var handleOpenURL = function(url) {
       // do stuff
   };
   
   document.addEventListener('deviceready', function() {
       // initialize app
   });
   ```
   
   I'm like 99% sure that would work just fine, as long as you declare the 
`handleOpenURL` where it is assigned as `myapp.js` file is parsed by the 
browser.
   
   If you do the following: :x:
   ```javascript
   document.addEventListener('deviceready', function() {
       var handleOpenURL = function(url) {
           // This will definitely cause a race condition
       };
       // initialize app
   });
   
   setTimeout(function() {
       var handleOpenURL = function(url) {
           // This will also cause a race condition, because handleOpenURL is 
being set asynchronously.
       };
   }, 0);
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to