PHImageFileURLKey returns null

enroubenroub USMember ✭✭

Hi. Is there any workaround for the PHImageFileURLKey that is returning null after update to iOS 12.1 and iOS 13?

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    PHImageFileURLKey is not available in iOS13 .

    You can get the description of a PHAssetResource object using +[PHAssetResource assetResourcesForAsset:] , use first object from resulting array and then extract the fileURL from string using regex:

    Refer https://stackoverflow.com/a/58003875/8187800.

  • enroubenroub USMember ✭✭

    Thanks @ColeX
    I followed what is said on the post. Though I noticed some things. Photos captured by the iPhone Camera does not have the fileUrl DebugDescription and the PHImageFileURLKey info. By the way, we are testing it on an iPhone X with iOS 12.4.1 and iPhone6s with iOS 13.1.2. The one on the iPhone 6s worked with the PHAssetResource while the one on the iPhoneX did not with both the PHAssetResource and PHImageFileURLKey. Do you happe to know any other way to get the file url of the captured image if it is on an iPhoneX?

  • ColeXColeX Member, Xamarin Team Xamurai

    Could you post the code how you get the images ? I have a iPhoneX and could test on my side .

  • enroubenroub USMember ✭✭
    private void Picker_FinishedPickingAssets(object sender, MultiAssetEventArgs args)
    {
        List<ImageModel> images = new List<ImageModel>();
        foreach (var asset in args.Assets)
        {
            var assetResources = PHAssetResource.GetAssetResources(asset);
            Regex fileURLpattern = new Regex(@"file:.*");
            string fileURL = string.Empty;
    
            foreach (var assetResource in assetResources)
            {
                var des = assetResource.DebugDescription;
                Match patternUrlMatch = fileURLpattern.Match(des);
                fileURL = patternUrlMatch.Groups[0].Value;
            }
        }
    }
    

    we used "file:.*" as our pattern since we saw the resulting string from the iPhone6 that it is only file and not fileURL. When we are using iPhoneX the fileURL or file on the string is not there so there is no matching pattern.

  • ColeXColeX Member, Xamarin Team Xamurai
    edited October 8

    Where > @enroub said:

    private void Picker_FinishedPickingAssets(object sender, MultiAssetEventArgs args)
    {
      List<ImageModel> images = new List<ImageModel>();
      foreach (var asset in args.Assets)
      {
          var assetResources = PHAssetResource.GetAssetResources(asset);
          Regex fileURLpattern = new Regex(@"file:.*");
          string fileURL = string.Empty;
    
          foreach (var assetResource in assetResources)
          {
              var des = assetResource.DebugDescription;
              Match patternUrlMatch = fileURLpattern.Match(des);
              fileURL = patternUrlMatch.Groups[0].Value;
          }
      }
    }
    

    we used "file:.*" as our pattern since we saw the resulting string from the iPhone6 that it is only file and not fileURL. When we are using iPhoneX the fileURL or file on the string is not there so there is no matching pattern.

    I test with my iPhoneX(iOS13.0) , it works fine , fileURL has value ,check my screen shot .

  • enroubenroub USMember ✭✭
    edited October 10

    Hi @ColeX, we just updated the iPhoneX to iOS13 and after we updated, the fileURL is there. We'll have to do more testing regarding this since some of our users still runs lower iOS versions. Thanks by the way.

  • ColeXColeX Member, Xamarin Team Xamurai
    edited October 10

    You could detect the version ,and do the different logic .

     if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
            {
                //new method
            }
            else
            {
                //old method
            }
    
Sign In or Register to comment.