iOS Question Loading files in debug and release

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.
 

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.
 

Haris Hafeez

Active Member
Licensed User
The code for loading a file using URL is this:

B4X:
-(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.

B4X:
-(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;
}
 

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.
 
Top