Posts

Post not yet marked as solved
0 Replies
468 Views
I am using Managed Settings to block all apps during a set period of time using the below method. override func intervalDidStart(for activity: DeviceActivityName) { super.intervalDidStart(for: activity) ManagedSettingsStore().shield.applicationCategories = .all() } When a user opens an app during that time, they should be allowed to press a button on the shield which lets them "continue using that app", just like the default iOS screen time allows for. However, this doesn't seem possible right now when the below delegate is called for ActivityCategoryToken ShieldAction: override func handle(action: ShieldAction, for category: ActivityCategoryToken, completionHandler: @escaping (ShieldActionResponse) -> Void) { switch action { case .primaryButtonPressed: completionHandler(.close) case .secondaryButtonPressed: ManagedSettingsStore().shield.applicationCategories = .all(except: category) //this is not possible right now. completionHandler(.none) @unknown default: fatalError() } } This is because the .all(except:) method takes a set of application tokens, but the handle delegate method on activityCategoryTokens only provides application category tokens. Is there no way to get around this? It would be very helpful if either a) the delegate method for ActivityCategoryToken ShieldAction also provided the ApplicationToken that was blocked (this would be preferred), or b) the .all(except: ) method also accepts ActivityCategoryTokens as an input.
Posted
by adamtwo.
Last updated
.
Post not yet marked as solved
0 Replies
549 Views
I am trying to mimic the flash behavior of a disposable camera on iPhone. With a disposable camera, when the capture button is clicked, the flash instantly and quickly goes off once, right as the photo is captured. However, with the iPhone’s camera, when the capture button is pressed, the torch is turned on for roughly a second, and then the sound is produced & torch flashes on & off as the photo is capture. When using the straightforward Apple API of setting the AVCapturePhotoSettings.flashMode to on: var photoSettings = AVCapturePhotoSettings() photoSettings.flashMode = .on the system default flash behavior is applied. Instead, I would like to create my own custom flash behavior which does not include the torch being turned on for roughly a second before it flashes again in order to mimic a disposable camera. My idea was to manually toggle the torch either right before or during the AVCapturePhotoOutput.capturePhoto() process. private let flashSessionQueue = DispatchQueue(label: "flash session queue") func toggleTorch(_ on: Bool) { let device = AVCaptureDevice.default(.builtInDualWideCamera, for: .video, position: .back)! do { try device.lockForConfiguration() device.torchMode = on ? .on : .off device.unlockForConfiguration() } catch { print("Torch could not be used") } } func photoOutput(_ output: AVCapturePhotoOutput, willBeginCaptureFor resolvedSettings: AVCaptureResolvedPhotoSettings) { flashSessionQueue.async { self.toggleTorch(true) } flashSessionQueue.asyncAfter(deadline: .now() + 0.2) { self.toggleTorch(false) } } However, when I do this, the photo is not actually captured, and instead I get either error “**AVFoundationErrorDomain Code=-11800". The flash does occur—the torch turns on and off—but no photo is captured. Would it even be possible to create a custom flash by manually toggling the torch before / during a camera capture? I have been doing research on AVCaptureMultiCamSession and am also wondering if that could provide a solution.
Posted
by adamtwo.
Last updated
.