Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALAsset in CDVURLProtocol.m is deprecated since iOS 9.0 #551

Closed
3 tasks done
maeisdev opened this issue Feb 26, 2019 · 2 comments
Closed
3 tasks done

ALAsset in CDVURLProtocol.m is deprecated since iOS 9.0 #551

maeisdev opened this issue Feb 26, 2019 · 2 comments
Labels
Milestone

Comments

@maeisdev
Copy link

maeisdev commented Feb 26, 2019

Bug Report

Problem

What is expected to happen?

Cordova what uses PHAsset from the Photos framework instead of deprecated ALAsset.

What does actually happen?

Cordova target is iOS 10, but in CDVURLProtocol.m uses deprecated API from before iOS 9.0.

Information

This causes XCode warnings, but code to refactoring is a few lines.

Command or Code

https://github.com/apache/cordova-ios/blob/master/CordovaLib/Classes/Public/CDVURLProtocol.m
This is deprecated code:

    if ([[url absoluteString] hasPrefix:kCDVAssetsLibraryPrefixes]) {
        ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset* asset) {
            if (asset) {
                // We have the asset!  Get the data and send it along.
                ALAssetRepresentation* assetRepresentation = [asset defaultRepresentation];
                NSString* MIMEType = (__bridge_transfer NSString*)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)[assetRepresentation UTI], kUTTagClassMIMEType);
                Byte* buffer = (Byte*)malloc((unsigned long)[assetRepresentation size]);
                NSUInteger bufferSize = [assetRepresentation getBytes:buffer fromOffset:0.0 length:(NSUInteger)[assetRepresentation size] error:nil];
                NSData* data = [NSData dataWithBytesNoCopy:buffer length:bufferSize freeWhenDone:YES];
                [self sendResponseWithResponseCode:200 data:data mimeType:MIMEType];
            } else {
                // Retrieving the asset failed for some reason.  Send an error.
                [self sendResponseWithResponseCode:404 data:nil mimeType:nil];
            }
        };
        ALAssetsLibraryAccessFailureBlock failureBlock = ^(NSError* error) {
            // Retrieving the asset failed for some reason.  Send an error.
            [self sendResponseWithResponseCode:401 data:nil mimeType:nil];
        };

        ALAssetsLibrary* assetsLibrary = [[ALAssetsLibrary alloc] init];
        [assetsLibrary assetForURL:url resultBlock:resultBlock failureBlock:failureBlock];
        return;
    }

Environment, Platform, Device

iOS

Version information

5.1

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@brody4hire brody4hire added the bug label Feb 26, 2019
@brody4hire
Copy link

Confirmed as a bug (see https://developer.apple.com/documentation/assetslibrary/alasset), thanks!

A pull request would definitely be welcome.

@brody4hire
Copy link

Seems to be resolved by PR #783

@erisu erisu closed this as completed Feb 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants