I am using AVMulti so the user captures two images how can I access those images if there is only one url that stores the captured images for the lockScreenCapture extension ? Plus how can I detect if the user opened the app from the extension to be able to navigate the user to the right screen ?
Hello @EngOmarElsayed,
the function you are referring to in the UIApplicationDelegate is didFinishLaunchingWithOptions right ?
I am referring to application(_:continue:restorationHandler:).
the second question is that how can I access the images in the directory ? like how can I know the name of the front and the back image ? if you can provide more context on how I can access the images from the directory will be very helpful.
You determine the structure of data written to the sessionContentURL. For example:
// My custom SessionContent.
let content = SessionContent(frontImage: "hello", backImage: "world")
// Encoded as json.
let json = try JSONEncoder().encode(content)
// sessionContentURL/content.json
let outputURL = session.sessionContentURL.appendingPathComponent("content", conformingTo: .json)
// Writing my data to the url.
try json.write(to: outputURL)
// Creating my user activity.
let activity = NSUserActivity(activityType: NSUserActivityTypeLockedCameraCapture)
// opening the application from the extension.
try await session.openApplication(for: activity)
Then, in the delegate method I referred to above, or if you are using SwiftUI onContinueUserActivity:
.onContinueUserActivity(NSUserActivityTypeLockedCameraCapture) { activity in
let manager = LockedCameraCaptureManager.shared
Task {
for await update in manager.sessionContentUpdates {
switch update {
case .initial(urls: let urls):
print("initial: \(urls)")
case .added(url: let url):
print("added \(url)")
let contents = try FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: nil)
// You should see the json file here.
print("Contents: \(contents)")
case .removed(url: let url):
print("removed: \(url)")
@unknown default:
break
}
}
}
}
-- Greg