iOS 14 NSItemProvider loadDataRepresentation() returns nil data for specified types - ios

Setup:
I am using PHPickerViewController to allow the user to select photos. I've implemented the PHPickerViewControllerDelegate protocol method picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]). I am getting the itemProvider from the results array.
Problem:
I need to access the data for the selected image. There is a method on NSItemProvider called loadDataRepresentation(), which takes a type identifier string and should return the image data in its completion block.
When I call this method sometimes it returns data, sometimes it doesn't. I've tried this for the multiple registered type identifiers for each provider, and I'm seeing the same thing. Sometimes it will return JPEG data, but not HEIF, other times only HEIF, and sometimes it won't return any data at all. This is consistent in that the same photo exhibits the same result each time I try to load its data.
When there is no data I see the following error:
Upload preparation for claim D8C281B7-CCCE-4299-95BF-9355FCF340E4 completed with error: Error Domain=NSCocoaErrorDomain Code=260 "The file “7AB1AB3F-7643-45C1-9DD9-5F5642965C3A.jpeg” couldn’t be opened because there is no such file."
Is there something I need to do to the photo before attempting to load its data? Maybe I'm missing a step here? This happens for photos I took directly with my iPhone XR. I am not using iCloud Photos, all photos are on the device.

"public.image" this identifier seems to be able to get all type of photos.
example : -
loadDataRepresentation(forTypeIdentifier: "public.image")

If you're getting this error in simulator it seems like it may be an OS bug, because doing a Device > Erase All Content and Settings.. to reset the simulator fixed this for me.

Related

UIImage imageWithContentsOfFile: not working on real device

I'm creating a tableView which contains the images from gallery picked by the user, then I take the selected imagePath to place it on an UIImageView.
To set an iOS gallery image in a UIImageView,
I'm using:
NSString *imgPath = #"/var/mobile/Media/DCIM/105APPLE/IMG_5903.JPG";//Hardcoded path just for test, image actually exists on iOS device
self.imgViewContainer.image = [UIImage imageWithContentsOfFile: imgPath];
This code which works on Simulator.
I tested on a real device and I noticed that the UIImageView is empty after execute the above code.
Is there a way to achieve this using a real device?
Due to app sandboxing, your app does not have permission to view the contents of /var/mobile/Media (or really any subdirectory of /var/). Consider the code below:
do {
let fileList = try FileManager.default.contentsOfDirectory(atPath: "/var/mobile/Media/DCIM/")
} catch {
print(error)
}
contentsOfDirectory(atPath:) with throw an error with these details:
Error Domain=NSCocoaErrorDomain Code=257 "The file “DCIM” couldn’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=/var/mobile/Media/DCIM/, NSUserStringVariant=(
Folder
), NSUnderlyingError=0x170045700 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}
This example is in Swift, but the equivalent Objective-C code would have the same error.
There is no way around this (unless your are using a jailbroken device running your application as the root user). Use UIImagePickerController to ask the user for an image.

Why SKProductsRequestDelegate/SKRequestDelegate didFailWithError throws EXC_BAD_ACCESS on NSError?

I use SKProductsRequest to download product infos from App Store.
When I test a connectivity loss on my device, the request fails, but my app crashes within the SKRequestDelegate when I try to NSLog the error:
What am I doing wrong ? Another curious thing to me is that Expression Inspector is able to display NSError.debugDescription...
It fails on the first request, so there is no possible bug relative to multiple uses of productRequest variable (which is a strong ref in my swift class).
I finally found the reason. It is not related to SKProductsRequest!
I think there is a nasty bug with NSLogand string interpolation because when I replace:
NSLog("Failed: \(error.debugDescription)")
by
print("Failed: \(error.debugDescription)")
all is fine!
Apparently, the content of the error message can provoke a EXC_BAD_ADDRESS in NSLog (even without string interpolation in fact: NSLog(error.debugDescription) fails too).
Related anwser: https://stackoverflow.com/a/29631505/249742
NSLog("%#", error.debugDescription)
seems to work fine in every cases.
Perhaps NSLog(variable) is a misuse of NSLog, but I think NSLog(\(variable)) should be interpreted like NSLog("%#", variable). Else, there is no reliable way to interpolate strings with NSLog using the swift way \().

getting error ContentBlockerErrorDomain Code=3 in adblocker

I am getting error in loading content blocker by creating group: When i provide list of small number of rules in content blocker the error didn't came, but when i add more rules in my blocker list it gives error, It means there is limit of data to provide on App Group? Any one followed some other approach please share
ContentBlockerErrorDomain Code=3
i think that you are facing this issue while using NSUserdefault
after setting object in UserDefault you need to synchronize it . that thing you missed:
once apply this :
NSUserDefaults.standardUserDefaults()["key"] = "value"
NSUserDefaults.standardUserDefaults().synchronize()

ContentExtensionsDomain error 1

I am trying to use "reloadContentBlockerWithIdentifier" function of SFContentBlockerManager as follows:
[SFContentBlockerManager reloadContentBlockerWithIdentifier:#"appid.extensionid"
completionHandler: ^ (NSError *error) {
NSLog("%#", error.localizedDescription)
}
However, it only returns error message that said as follows:
The operation couldn’t be completed. (ContentExtensionsDomain error 1.)
I set both APP IDs (appid and appid.appextensionid) in "Certificates, Identifiers & Profiles" in developer.apple.com. Also, I made two "target"s for each -- ios app and ios app extension. I also checked open source implementations in Github which are roughly the same as mine, and App Extension manual several times, but it seems hard to find the relevant page for this problem. The most critical problem is: I couldn't find any offcial documents describing this message.
I'd appreciate if you let me know what is the problem.
Looking at the safari services generated swift interface, I could find the following enum for error codes:
public enum SFContentBlockerErrorCode : Int {
case NoExtensionFound
case NoAttachmentFound
case LoadingInterrupted
}
So in your case it's probably the NoAttachmentFound error. Which can be caused by failure to initialise an item provider with given data from a json file.

FBDialog Photo Sharing issue

I am sharing photo usingFBDI presentShareDialogWithPhotoParams /presentShareDialogWithPhotos method in FBDialogs. This method shares photo successfully on my wall but always returns an error, meaning that it posts photos with an NSError.
Error is like....
Error Domain=com.facebook.Facebook.platform Code=103 "The operation couldn’t be completed.
(com.facebook.Facebook.platform error 103.)"
UserInfo=0x16d874f0 {error_code=103, error_description=An unknown error occurred., app_id=593434950703264, error_reason=( { result = 1; } )}
Why this happen?
I believe this answer will get deleted like my previous one, but anywho...
The issue have been fixed!!!,
just update your Facebook app to v20,
released on December 8th.
See:
Code=103 "The operation couldn’t be completed ..." in Share Photo
note:
I want to add comment to the question but I don't have the privilege to do that,
so I add an answer instead.
Yesterday, I came across the same issue, the strange thing was that is even after this error comes, just check your Facebook (for which you've shared a content), and yes you'll feel awesome, the content is already uploaded (shared) on Facebook. I'm also looking forward for this issue, in my checks this problem will only occurring if you're using this method + (FBAppCall *)presentShareDialogWithPhotoParams:(FBPhotoParams *)params clientState:(NSDictionary *)clientState handler:(FBDialogAppCallCompletionHandler)handler; from FBDialogs.h means, using of Facebook application dialog for sharing.

Resources