Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19833] Allow users to access images via Ti.Filesystem when app thinning is enabled

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-01-11T21:22:27.000+0000
Affected Version/sRelease 5.1.0
Fix Version/sRelease 5.4.0
ComponentsiOS
Labelsappthinning, qe-5.4.0
ReporterFokke Zandbergen
AssigneeChee Kiat Ng
Created2015-10-30T10:34:57.000+0000
Updated2016-07-26T23:14:08.000+0000

Description

Because of TIMOB-19757 we have made app-thinning of image assets optional (for existing projects). This means that when a developer needs to have access to an image via Ti.Filesystem.getFile() he has to disable app-thinning for *all* images. We need a better solution for this. Some thoughts: * Provide away to exclude images from asset catalogs ** (n) Requires new folder or meta file * Modify Ti.Filesystem.getFile() to find images in asset catalogs ** (n) Requires hack to recognise image requests under resourceDirectory and translate that to [UIImage imageNamed:@"my-name"]; * Add Ti.Filesystem.getAsset() to get an asset via [UIImage imageNamed:@"my-name"]; ** (y) Looks like the best option.

Comments

  1. Chee Kiat Ng 2016-01-07

    Ti.Filesystem.getAsset(file path of bundled image) shall return a blob. This makes the method more versatile, allowing the developer the choice of saving it as a file in any location.
  2. Chee Kiat Ng 2016-01-07

    PR here: https://github.com/appcelerator/titanium_mobile/pull/7622

    Steps to test:

    1. create a new classic project 2. include in tiapp.xml
       	<ios>
           	<use-app-thinning>true</use-app-thinning>
       
    3. include any image, foo.png in *Resources/images/foo.png* 4. Run this sample code Sample Code:
       var win = Ti.UI.createWindow({
       	backgroundColor: '#fff'
       });
       
       var imageView = Ti.UI.createImageView();
       win.add(imageView);
       
       //get image blob using getAsset
       var imageBlob = Ti.Filesystem.getAsset('images/foo.png');
       
       //create a file based on the blog
       var filename = Ti.Filesystem.applicationDataDirectory + 'blog_image.png';
       f = Ti.Filesystem.getFile(filename);
       f.write(imageBlob);
       Ti.API.info(f);
       
       //set image on imageView based on file
       imageView.setImage(f);
       
       win.open();
       

    Expected Result

    You will see the image shown in the imageView.

    Extra Tests

    you can include more images named *foo@2x.png*, *foo~iphone.png* and retest with *Ti.Filesystem.getAsset('images/foo@2x.png')* and *Ti.Filesystem.getAsset('images/foo~iphone.png')* respectively, you will still see the image.
  3. Fokke Zandbergen 2016-01-07

    [~cng] I don't even think we could return a file since assets in asset catalogs (except for AppIcon and LaunchImage) are compressed into a single Assets.car file? I assume writing to a file in the example is for the purpose of demonstration since you could just assign the blob to the ImageView's image property as well?
  4. Chee Kiat Ng 2016-01-07

    Yes that was my intention.
  5. Angel Petkov 2016-01-11

    FT and CR approved. Thanks Kiat! Merging.
  6. Josh Longton 2016-07-26

    Verified as fixed, I am now able to access images using Ti.Filesystem when app thinning is enabled. Tested on:
       iPhone 6s (9.3.1) 
       iOS simulator (9.3)
       
Mac OSX El Capitan 10.11.6
       Studio: 4.7.0.201607130543
       
Ti SDK: 5.4.0.v20160725003348
       
Xcode: 7.3.1 
       
Appc NPM: 4.2.7
       Appc CLI: 5.4.0-35
       Node: v4.4.4
       
    *Closing ticket*

JSON Source