开发者

iPad app pauses during build

开发者 https://www.devze.com 2023-03-29 09:14 出处:网络
The app is a gallery app that creates an image in the Documents folder on the iOS device file system. It stores image data into a sqlite database.

The app is a gallery app that creates an image in the Documents folder on the iOS device file system. It stores image data into a sqlite database.

I'm trying to put an iPad app onto the device but every time during the build process, the app would just say "paused" in the "By Thread" panel in Xcode 4 and it stops building the app.

However, when I build the app for the iPad simulator, it went through fine. I see the final app on the simulator and it doesn't crash.

My app reads a list of URL from a txt file, constructs an image from the URL as well as a thumbnail representation of that image and saves them into the Documents folder. Then it stores the URL to the full size image into a sqlite3 database.

I have read and tried disabling PNG compression like how this guy here did it:

iOS - Build Freezes When I Build To Device but Not in Simulator

but that didn't fix it, it still freeze duing the build.

I've checked my text file and the line it stops reading has the same structure as the other lines.

Has anyone had this problem?

Update

Ran my app through Instruments and it seems like I have a CFString that keeps accumulating somehow.

I think it's my database and how I keep inserting more data into it.

Do you guys see anything wrong with this code:

- (void) insertImageWithImageNumber:(int) imageNumber URL:(NSString *) url ImageDesciption:(NSString *) description andGalleryNumber:(int) galleryNumber
{
    NSString *imageName = [[NSString alloc] initWithString:[url lastPathComponent]];
    NSURL *imageURL = [[NSURL alloc] initWithString:url];
    NSData *imageData = [[NSData alloc] initWithContentsOfURL:imageURL];

    // writing the image file to the Documents folder of this app
    [[NSFileManager defaultManager] createFileAtPath:[MediaDirectory mediaPathForFileName:imageName] contents:imageData attributes:nil];

    NSString *imagePath = [[NSString alloc] initWithString:[MediaDirectory mediaPathForFileName:imageName]];

    //NSLog(@"Image stored in location: %@", imagePath);

    const char *sqlCommand = "INSERT INTO galleryImages (imageNumber, imageURL, imageDescription, galleryNumber) VALUES (?, ?, ?, ?);";

    sqlite3_stmt *statement;

    sqlite3_prepare_v2(database, sqlCommand, -1, &statement, nil);
    sqlite3_bind_int(statement, 1, imageNumber);
    sqlite3_bind_text(statement, 2, [imagePath UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(statement, 3, [description UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_int(statement, 4, galleryNumber);

    sqlite3_step(statement);
    sqlite3_finalize(statement);

    UIImage *thumbnailImage = [[UIImage alloc] initWithData:imageData];

    // creating thubmanil of the full size image and storing them
    UIGraphicsBeginImageContext(CGSizeMake(thumbnailImage.size.width / 4.0, thumbnailImage.size.height / 4.0));

    // redraw the image in a smaller size (resizing the image)
    [thumbnailImage drawInRect:CGRectMake(0, 0, thumbnailImage.size.width / 4.0, thumbnailImage.size.height / 4.0)];

    // making a new thumbnail image from current context
    UIImage *newThumbnailImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    // getting the binary data for the thumbnail image so we can write it to disk later
    NSData *thumbnailData = UIImagePNGRepresentation(newThumbnailImage);

    // write the thumbnail image to disk
    NSString *thumbnailName = [[NSString alloc] initWithFormat:@"%@_thumb.%@", [imageName stringByDeletingPathExtension], [imageName pathExtension]];

    //NSLog(@"Thumbnail path = %@", [MediaDirectory mediaPathForFileName:thumbnailName]);

    [thumbnailData writeToFile:[MediaDirectory mediaPathForFileName:thumbnailName] atomically:NO];

    [thumbnailImage release];
    [thumbnailName release];
    [imagePath release];
    [imageData release];
    [imageURL release];
    [imageName release];
}

More Update

I decided rework my program design and create my thumbnail images on the fly after creating inserting all my image into my d开发者_运维知识库atabase. So after the loop that inserts image data, I have another loop that builds the thumbnail images and add it to the interface.

I guess reworking my design is one solution :)

0

精彩评论

暂无评论...
验证码 换一张
取 消