AVCapturePhotoCaptureDelegate Error When Capturing Image - ios

I seem to get this error message randomly after a few cycles of capture:
Error finishing photo: Error Domain=AVFoundationErrorDomain
Code=-11800 "The operation could not be completed"
UserInfo={NSLocalizedFailureReason=An unknown error occurred (-16802),
NSLocalizedDescription=The operation could not be completed,
NSUnderlyingError=0x281f20f30 {Error Domain=NSOSStatusErrorDomain
Code=-16802 "(null)"}}
Error occurs in:
func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {}
Notes:
This Error never comes up on the first capture.
The image format is also a processed format: HEIF
iOS 13

Had the same issue, the culprit was stabilization. I was setting
settings.isAutoStillImageStabilizationEnabled = true
while capturing the image. Stabilization is a heavy process which on main thread which hinders the buffer allocation. Moved it to where camera was getting initialized, resolved the issue for me.

Related

iOS 16 FairPlay Changes

Are there any changes in FairPlay logic? My app has FairPlay protected Videos and Audio, they work perfectly until iOS 15.7, but in iOS 16
makeStreamingContentKeyRequestData is throwing me following error :
Error Domain=CoreMediaErrorDomain Code=-19152 "(null)"
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed"
UserInfo={NSLocalizedFailureReason=An unknown error occurred (-19156), NSLocalizedDescription=The operation could not be completed,
NSUnderlyingError=0x280deac10 {Error Domain=NSOSStatusErrorDomain Code=-19156 "(null)"}}
What could be the possible reason for this and solution?
Thanks in Advance
Function streamingContentKeyRequestDataForApp is deprecated on iOS 15 according to documentation. Use function makeStreamingContentKeyRequestData that is specified in new function documentation. Here is an example usage:
func makeStreamingContentKeyRequestData(
forApp appIdentifier: Data,
contentIdentifier: Data?,
options: [String : Any]? = nil,
completionHandler handler: #escaping (Data?, Error?) -> Void
)
We are using AVContentKeySession for downloading, met with the same error, and fixed it. For our case, the issue was as following.
Issue observed:
On iOS16.0.3, 12s later after "license request" was triggered firstly by app during downloading, "license request" would be triggered again by AVFoundation framework
("contentKeySession(_ session: AVContentKeySession, didProvide keyRequest: AVContentKeyRequest)" was called again), and then error “-19152“ wad reported quickly by framework.
Error log:
contentKeySession(_:contentKeyRequest:didFailWithError:), line: XXX,
message: XXX, url: XXX, error is Domain=CoreMediaErrorDomain
Code=-19152 "(null)"
On iOS15.6.1, after "license request" was triggered
by app during downloading, framework would not trigger any "license request" again.
Root cause:
iOS Framework API(AVContentKeySession & AVPersistableContentKeyRequest) behaviors changed on iOS16.
Solution:
Add “keyRequest.processContentKeyResponse(keyResponse)” after CKC has been downloaded on iOS16+.
On iOS11 - iOS15, we didn't call it after downloading, instead we only save persistentKeyData locally, and called processContentKeyResponse when playing. That always worked fine on these iOS versions.
But on iOS16 and above(until iOS16.1 Beta4 by now), the old process would trigger framework error. So we added this fix.
The issue I had was that the keyRequest.options was not getting set as it showed up nil (in iOS 16 for whatever weird reason).
I'm passing the correct options to
processContentKeyRequest(withIdentifer identifier: Any?, initializationData: Data?, options: [String : Any]? = nil).
But in the ContentKeyDelegate functions they are showing otherwise. So, my workaround is just using a global options dictionary for storing the license URL and asset data. You can use any storage method you prefer.
I have solved the issue, the issue was with duplicate EXT tags in m3u8 files which somehow worked for iOS 15 since it picked information from the first tag whereas in iOS 16 it was using all the tags and causing a Error

CHHapticEngine not running

After a day of playing with the CHHapticEngine and custom haptic patterns, using AHAP files in particular (including adding sound samples), I have lost the sound and haptics in the deivce / iPhone. After a factory reset of the iPhone, there are still no haptics / sound in the device (no ringer, no vibrations etc.). When trying to start the haptics engine and play any pattern I can see the following output in the Xcode debugger:
2020-04-29 19:44:31.034051+0200 ProjectName[18431:5043001] [hapi] CHHapticEngine.mm:2354:-[CHHapticEngine doStartWithCompletionHandler:]_block_invoke: ERROR: Player start failed: The operation couldn’t be completed. (com.apple.CoreHaptics error 1852797029.)
2020-04-29 19:44:31.034398+0200 ProjectName[18431:5042880] [Feedback] failed to start core haptics engine for <_UIFeedbackCoreHapticsEngine: 0x28268f170>: Error Domain=com.apple.CoreHaptics Code=1852797029 "(null)"
2020-04-29 19:44:34.076491+0200 ProjectName[18431:5043124] [hapi] CHHapticEngine.mm:2354:-[CHHapticEngine doStartWithCompletionHandler:]_block_invoke: ERROR: Player start failed: The operation couldn’t be completed. (com.apple.CoreHaptics error 1852797029.)
2020-04-29 19:44:34.076703+0200 ProjectName[18431:5043124] [hapi] HapticUtils.h:56:_Haptic_Check: -[CHHapticEngine checkEngineState:]: self.running error -4805
2020-04-29 19:44:34.077641+0200 ProjectName[18431:5043124] error = Error Domain=com.apple.CoreHaptics Code=-4805 "(null)" UserInfo={Error =self.running}
The question is, is it probable to damage the hardware from code?

MPMusicPlayerController setCurrentPlaybackRate

The call to setCurrentPlaybackRate to the MPMusicPlayerController stopped working after the latest iOS update, and now gives this error:
2018-04-15 16:24:06.904562-0600 SampleProject[5659:1836398] [SDKPlayback] -
[MPMusicPlayerController setCurrentPlaybackRate:0.670213] completed error:
Error Domain=MPCPlayerRequestErrorDomain Code=1 "No commands provided."
UserInfo={NSDebugDescription=No commands provided.}
I'm passing in a valid double value greater than 0 and less than 2.
This is the call:
[appMusicPlayer setCurrentPlaybackRate:0.7];
Thanks for any input or help!
P.S. I'm getting a lot of other weird errors too. Here are some:
2018-04-15 17:30:01.976932-0600 SampleProject[5733:1868672] [SDKPlayback]
Failed validators: {(
setRepeatMode
)}
2018-04-15 17:30:03.976879-0600 SampleProject[5733:1868672] [SDKPlayback]
Failed to get a valid response. Resetting expectations.
2018-04-15 17:30:01.976932-0600 SampleProject[5733:1868672] [SDKPlayback]
Failed validators: {(
setRepeatMode
)}
2018-04-15 17:30:03.976879-0600 SampleProject[5733:1868672] [SDKPlayback]
Failed to get a valid response. Resetting expectations.
I just encountered the same issue when trying to use player.append(MPMusicPlayerQueueDescriptor). I found that it would return the same error when the queue for my MPMusicPlayerController was quite large. When I cut it down to around 10, it works with no issues. I haven't experimented to see the maximum I can add to the queue.
I hope this helps, perhaps a smaller queue will also work for you.

AVCaptureDevice flashMode not working

In an app using AVCaptureSession and AVCaptureDevice, I am taking pictures and it goes as expected.
I decided to implement the use of the flash and there troubles are coming.
Here is the code I added, after searching on the net on how to use the flash in an iOS app:
if captureDevice.hasFlash && captureDevice.isFlashModeSupported(.On) {
do {try captureDevice.lockForConfiguration()
} catch let error as NSError {
print("captureDevice.lockForConfiguration FAILED")
print(error.code)
}
captureDevice.flashMode = .On
captureDevice.unlockForConfiguration()
captureSession.commitConfiguration()
}
It compiles OK but when I try to take a photo, the app crashes with the following error:
Error on taking a picture:
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation couldn’t be completed." UserInfo={NSUnderlyingError=0x14e176f40 {Error Domain=NSOSStatusErrorDomain Code=-16800 "(null)"}, NSLocalizedFailureReason=Undefined error(-16800), NSLocalizedDescription=The operation couldn’t be completed.}
Since I have never used the flash before, it may well be a newbie error. But I haven’t, at this point, been able to figure out what was wrong.
If anyone has experience using the flash in an app, please let me know what may be the issue.

AVAssetWriter error when AVCaptureSession camera input is changed

I use AVCaptureSession getting live data from camera and AVCaptureVideoDataOutput & AVCaptureAudioDataOutput delegates in order to get live data frame by frame. (-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection). I sent sample buffer frames (CMSampleBufferRef) that are taken from captureOutput:didOutputSampleBuffer:fromConnection: method to the AVAssetWriter's appendSampleBuffer: method in order to save the taken buffers as video file. But AVAssetWriter instance's status becomes to AVAssetWriterStatusFailed when back camera is toggled to front camera and try to appendSampleBuffer: with the sample buffer that is received from front camera.
The exact error message is:
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x176573f0 {NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x175e9e50 "The operation couldn’t be completed. (OSStatus error -12710.)", NSLocalizedFailureReason=An unknown error occurred (-12710)}
What can be the problem?
Thanks in advance...

Resources