Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17582] iOS: Unable to check if a JS source file exists on iPad device

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2014-11-27T07:15:21.000+0000
Affected Version/sn/a
Fix Version/sRelease 3.4.2, Release 3.5.0, Release 4.0.0
ComponentsiOS
Labelsmodule_filesystem, qe-manualtest
ReporterEduardo Gomez
AssigneeChee Kiat Ng
Created2014-09-01T12:54:54.000+0000
Updated2014-12-19T16:36:16.000+0000

Description

Issue description

Not able to check if a JS source file exists in the app. It only worked in the iOS simulator but not the ipad device. This was initially reproduced on Alloy but attached is a Classic app sample.

Steps to replicate

1) Please grab the sample attached "CaseClassic2559.zip" and launch at iOS Simulator (for Alloy, you may want to use "Case2559.zip"). 2) Notice when compiled in the iOS ipad simulator, you will see "I'm Ipad". But it will show "This is Not Ipad" in the real ipad device.

Additional details

Alloy 1.4.1 - iPad OS 7.0.4. Also on TiSDK 3.4.0 CI and Alloy 1.6.0-dev.

Attachments

FileDateSize
Case2559.zip2014-09-01T12:54:54.000+00005919590
CaseClassic2559.zip2014-09-01T12:54:54.000+00003139694

Comments

  1. Joshua Rhinehart 2014-09-02

    The sample works on Simulator, but the file.exists() call fails on device. If you pull the name = controllerName; out of the if loop, it works as expected.
  2. Ingo Muschenetz 2014-09-03

    Is there a way we can just past the sample directly in the ticket? I don't think we need all the supporting files.
  3. Joshua Rhinehart 2014-09-03

    The Alloy index.js is as follows:
    var createController = Alloy.createController;
       
       /**
        * Override the Alloy createController method.
        * 
        * Prepends 'ipad/' to the controller name if the controller exist in the ipad folder
        */
       Alloy.createController = function(name, args) {
           var osname = Ti.Platform.osname;
           alert(osname);
           var controllerPath = Ti.Filesystem.resourcesDirectory + 'alloy/controllers/';
           // search controller in the os name folder
           var controllerName = osname + '/' + name;
           var file = Ti.Filesystem.getFile(controllerPath, controllerName + '.js');
           Ti.API.log(file.name);
           // load the controller in the platform folder if found, other load the default
           if (file.exists()) {
               name = controllerName;
           }
           
           Ti.API.log(controllerPath);
           Titanium.API.log('Controller Name: ' + name);
           return createController(name, args);
       };
       
       /**
        * Loads "ipad/HelloWorld.js" for ipad, and "HelloWorld.js" for other devices
        */
       var controllerName = 'HelloWorld';
       var label = Alloy.createController(controllerName).getView();
       
       $.index.add(label);
       $.index.open();
    and the corresponding app.js from the classic project is here:
    var getController = function(name) {
           var osname = Ti.Platform.osname;
           if(osname == 'ipad'){
           	name = 'HelloWorld';
           	Ti.API.info('iPad this time');
           }
           var controllerPath = Ti.Filesystem.resourcesDirectory + 'alloy/controllers/';
           // search controller in the os name folder
           var controllerName = osname + '/' + name;
           var file = Ti.Filesystem.getFile(controllerPath, controllerName + '.js');
           Ti.API.info(name +' controllerPath + controllerName: '+ controllerPath + controllerName );
           // load the controller in the platform folder if found, other load the default
           //if (file.exists()) {
               name = controllerName;
               Ti.API.info('file.nativePath: '+ file.nativePath);
               return require('alloy/controllers/' + controllerName).HelloWorld();
           // }else{
           	// Titanium.API.log('Controller Name: ' + controllerName);
           	// return require('alloy/controllers/' + controllerName).HelloWorld();    	
           // }
           
       };
       
       /**
        * Loads "ipad/HelloWorld.js" for ipad, and "HelloWorld.js" for other devices
        */
       var controllerName = 'HelloWorld';
       var label = getController(controllerName);
       
       win1.add(label);
       
       win1.open();
  4. Chee Kiat Ng 2014-10-14

    It is discovered that resourcesDirectory doesn't return a reliable result when utilized on iPad devices specifically. After some investigation, it is due to the use of [[NSBundle mainBundle] bundlePath]. Instead of absoluteString, path is recommended to be used when obtaining the path string for NSFileManager according to apple docs. By doing so, the resourcesDirectory returned reliable results for devices and simulators. PR here: https://github.com/appcelerator/titanium_mobile/pull/6213
  5. Vishal Duggal 2014-11-03

    PR's merged master - https://github.com/appcelerator/titanium_mobile/pull/6300 3_4_X - https://github.com/appcelerator/titanium_mobile/pull/6301
  6. Satyam Sekhri 2014-11-26

    The correct js source file path is evaluated/fetched for both iPad simulator and device. Verified on: SDK: 3.5.0.v20141125154115 Studio: 3.4.1.201410281743 CLI: 3.4.1 Alloy: 1.5.1 Device: iPad simulator (8.1), iPad 2(v7.1.2), ipad 4(v8.0) Xcode: 6.1

JSON Source