iOS Question Loading files in debug and release

Discussion in 'iOS Questions' started by Haris Hafeez, Jun 15, 2015.

  1. Haris Hafeez

    Haris Hafeez Active Member Licensed User

    Hi,

    So I developed this library for showing animated gifs which works fine in debug but in release the image view doesn't work. The library was using the load data from URL method to get the gif contents.

    I then created another method in the library that loads the data using NSBundle. This method takes the file name only and works fine when used in release mode but not debug.

    This situation leads me to believe that there appears to be some difference between the way b4i shell app in debug handles the file:// URL for loading image data. Also I can't quite understand why the method that uses NSBundle doesn't work in debug but works in release. I could be completely off though.

    I want to update the library so that we have one method that works for both debug and release for the users. So any help will be appreciated by all users.

    The library is HHAnimatedGifView by the way.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    The best way to load files is by using B4IFile from the Core library. It will take care of loading the file from the correct place.
     
  3. Haris Hafeez

    Haris Hafeez Active Member Licensed User

    Thanks for the tip. I have changed the library so that it uses B4IFile. However, would appreciate to know if the following is a good approach:

    • I take as input parameters the location(File.DirAssets etc) and file name.
    • I create a byte output stream and copy the file to it using B4IFile Copy2.
    • I use the byte data from the output stream to get the NSData to store the gif image data that is required by the image view.
    Is this OK? I will release an update to the library if we're comfortable it is coded well(enough).

    Cheers.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Not sure that these are the best steps. Can you post the code that works with the file?
     
  5. Haris Hafeez

    Haris Hafeez Active Member Licensed User

    The code for loading a file using URL is this:

    Code:
    -(UIImageView *) GetAnimatedGifViewForFile: (NSString *)GifFileName {
        FLAnimatedImage *
    image = [[FLAnimatedImage alloc] initWithAnimatedGIFData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:GifFileName ofType:@"gif"]]];
        FLAnimatedImageView *
    imageView = [[FLAnimatedImageView alloc] init];
        
    imageView.animatedImage = image;
        
    return imageView;
    }
    The code that I wrote to use B4IFile is below. The file location is the one of the constants like File.DirAssets. This method works well for files both in debug and release and loads the files correctly as you mentioned above.

    Code:
    -(UIImageView *) GetAnimatedGifViewUsingFile: (NSString *)FileLocation :(NSString*)FileName {
        B4IFile *bif = [B4IFile alloc];
        B4IInputStream *
    is = [bif OpenInput:FileLocation :FileName];
        B4IOutputStream *os = [B4IOutputStream alloc];
        [os InitializeToBytesArray:
    0];
        [bif Copy2:
    is :os];
        B4IArray *arr = [os ToBytesArray];
        NSData* data = [arr bytesData];
        [os Close];
     
        FLAnimatedImage *
    image = [[FLAnimatedImage alloc] initWithAnimatedGIFData:data];
        FLAnimatedImageView *
    imageView = [[FLAnimatedImageView alloc] init];
        
    imageView.animatedImage = image;
        
    return imageView;
    }
     
  6. Haris Hafeez

    Haris Hafeez Active Member Licensed User

    Can I get some advice on this please? Apologise to bump it up but I wanted to modify it and release it if this is good.

    Thanks.
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    The code looks fine.
     
    Haris Hafeez likes this.
Loading...