Load images from NSURL async with RestKit

后端 未结 2 1814
余生分开走
余生分开走 2021-02-09 17:39

Is there a wrapper or some sort of built-in functionality available in RestKit to load a UIImage from an NSURL asynchronously using callba

2条回答
  •  别跟我提以往
    2021-02-09 18:10

    Using RestKit you can use RKRequest to load the data for the image in a manner such as:

    RKRequest* request = [RKRequest requestWithURL: url];
    
    request.onDidLoadResponse = ^(RKResponse* response) {
        UIImage* image = [UIImage imageWithData: response.body];
        // do something interesting with the image
    };
    
    request.onDidFailLoadWithError = ^(NSError* error) {
        // handle failure to load image
    }
    
    [imageLoadingQueue addRequest: request];
    

    Note that even in the onDidLoadResponse case you may want to check response to make sure the type of data is what you expected. The image loading queue used above can be created like so:

    imageLoadingQueue = [RKRequestQueue requestQueueWithName: @"imageLoadingQueue"];
    [imageLoadingQueue start];
    

提交回复
热议问题