You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2019/02/26 20:18:37 UTC

[GitHub] maedewiza opened a new issue #551: ALAsset in CDVURLProtocol.m is deprecated since iOS 9.0

maedewiza opened a new issue #551: ALAsset in CDVURLProtocol.m is deprecated since iOS 9.0
URL: https://github.com/apache/cordova-ios/issues/551
 
 
   # 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
   <!-- Include all relevant information that might help understand and reproduce the problem -->
   This causes XCode warnings, but code to refactoring is a few lines.
   
   
   ### Command or Code
   <!-- What command or code is needed to reproduce the problem? -->
   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
   <!-- In what environment, on what platform or on which device are you experiencing the issue? -->
   iOS
   
   
   ### Version information
   <!-- 
   What are relevant versions you are using?
   For example:
   Cordova: Cordova CLI, Cordova Platforms, Cordova Plugins 
   Other Frameworks: Ionic Framework and CLI version
   Operating System, Android Studio, Xcode etc.
   -->
   5.1
   
   
   ## Checklist
   <!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
   
   - [x] I searched for existing GitHub issues
   - [x] I updated all Cordova tooling to most recent version
   - [x] I included all the necessary information above
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org