AVCaptureDevice flashMode not working - ios

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.

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?

AVCapturePhotoCaptureDelegate Error When Capturing Image

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.

Failure to save data to HealthKit (Cocoa error 4097)

I'm currently having difficulty saving data to health kit and I'm unsure what the problem is. I have health kit enabled and have granted read and write permissions on my testing device when the app runs (everything looks OK and I'm able to query the health kit database without error). I'm using Swift.
The code I'm using to save is:
hksaver.healthStore!.saveObjects(samples, withCompletion: {
(success: Bool , error: NSError!) -> Void in
if success { ... } else {
println("Failed to save. Error: \(error)")
}
samples is an array of HKQuantity Samples. It is created by appending 'dataSample' as defined below:
let dataPoint = HKQuantity(unit: units, doubleValue: measurement.dataPoint)
let dataSample = HKQuantitySample(type: quantityType,
quantity: dataPoint, startDate: measurement.startDate,
endDate: measurement.endDate, metadata: metadata)
There are no errors when constructing this, so I believe that all the values are appropriate.
When I run, I'm getting the following error:
Failed to save. Error: Error Domain=NSCocoaErrorDomain Code=4097 "The
operation couldn’t be completed. (Cocoa error 4097.)" (connection to
service named com.apple.healthd.server) UserInfo=0x17047a0c0
{NSDebugDescription=connection to service named
com.apple.healthd.server}
I'm trying to write ~100,000 values to HealthKit though I haven't been able to find any limits (the same error occurred when I was trying to write ~50,000 values). I've tried to write this in chunks, but after around 5 calls to health kit it starts failing (I'm assuming there is a limit to prevent continuous calls although I haven't seen anything in any documentation I've looked at).
I've tried searching under the error code, under the entire error, and under everything I could think of to explain the problem. The only results I've returned deal with HomeKit and tend to be that it is not activated. However under the capabilities tab I have HealthKit turned on and everything is check marked so I don't think that is the problem.
Any thoughts would be appreciated!

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