I’m sharing an caf format audio file, the share sheet could be opened and the file could be saved successfully in my iPhone, e.g. Save to Files. But Xcode have the following complain though. The file is located in app’s sandbox(DocumentDirectory). Should I add any privacy string in info.plist? Please help, guys.
Got error when executing windowScene.windows.first?.rootViewController?.present(activityViewController, animated: true, completion: nil)
in below code.
Failed to request default share mode for fileURL:file:///var/mobile/Containers/Data/Application/E13E4199-A782-4A29-8F13-A3568CCDD7B1/Documents/speakhby_exported_audio_20240623_174455.caf error:Error Domain=NSOSStatusErrorDomain Code=-10814 “(null)” UserInfo={_LSLine=1741, _LSFunction=runEvaluator}
Only support loading options for CKShare and SWY types.
error fetching item for URL:file:///var/mobile/Containers/Data/Application/C2BEA3CC-01DA-46E2-919A-42A7000C121F/Documents/speakhby_exported_audio_20240623_172629.caf : Error Domain=NSCocoaErrorDomain Code=256 “The file couldn’t be opened.”
Error acquiring assertion: <Error Domain=RBSServiceErrorDomain Code=1 “(originator doesn’t have entitlement com.apple.runningboard.primitiveattribute AND originator doesn’t have entitlement com.apple.runningboard.assertions.frontboard AND target is not running or doesn’t have entitlement com.apple.runningboard.trustedtarget AND Target not hosted by originator)” UserInfo={NSLocalizedFailureReason=(originator doesn’t have entitlement com.apple.runningboard.primitiveattribute AND originator doesn’t have entitlement com.apple.runningboard.assertions.frontboard AND target is not running or doesn’t have entitlement com.apple.runningboard.trustedtarget AND Target not hosted by originator)}>
(501) personaAttributesForPersonaType for type:0 failed with error Error Domain=NSCocoaErrorDomain Code=4099 “The connection to service named com.apple.mobile.usermanagerd.xpc was invalidated: failed at lookup with error 159 – Sandbox restriction.” UserInfo={NSDebugDescription=The connection to service named com.apple.mobile.usermanagerd.xpc was invalidated: failed at lookup with error 159 – Sandbox restriction.}
func shareFile(_ fileName: String) {
guard let fileURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent(fileName) else {
print("File not found!")
return
}
if FileManager.default.fileExists(atPath: fileURL.path) {
let activityViewController = UIActivityViewController(activityItems: [fileURL], applicationActivities: nil)
// Find the current window scene
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
// On iPad, you need to specify a source view when presenting the activity view controller
activityViewController.popoverPresentationController?.sourceView = windowScene.windows.first?.rootViewController?.view
// Present the view controller
// Pop errors when executing this line
windowScene.windows.first?.rootViewController?.present(activityViewController, animated: true, completion: nil)
} else {
print("No window scene found")
}
} else {
print("File not found!")
}
}