Using latest iOS and Xcode, I have an AppIntent to which Im passing a video file from iOS Shortcuts, Im using an IntentFile parameter to read that in the intent. Then Im using FFmpeg-iOS to generate a single frame from the video.
...
@Parameter(title: "Media", supportedTypeIdentifiers: ["public.image", "public.video"], inputConnectionBehavior: .connectToPreviousIntentResult)
var media: IntentFile
...
let mediaPath = media.fileURL!.absoluteString;
let posterPath = mediaPath.replacingOccurrences(of: media.filename, with: "poster.jpg")
_ = ffmpeg(["FFmpeg-iOS", "-i", mediaPath, "-frames:v", "1", posterPath])
Here is the output:
ffmpeg(_:) ["FFmpeg-iOS", "-i", "file:///var/mobile/tmp/com.apple.WorkflowKit.BackgroundShortcutRunner/IMG_2751.mov", "-frames:v", "1", "file:///var/mobile/tmp/com.apple.WorkflowKit.BackgroundShortcutRunner/poster.jpg"]
ffmpeg version N-109970-g7dc0944ce2 Copyright (c) 2000-2023 the FFmpeg developers
built with Apple clang version 14.0.0 (clang-1400.0.29.202)
configuration: --prefix=/Users/changbeomahn/Projects/FFmpeg-iOS/build/install/FFmpeg/arm64 --enable-cross-compile --disable-debug --disable-doc --enable-pic --disable-audiotoolbox --disable-sdl2 --disable-libxcb --target-os=darwin --arch=arm64 --cc='xcrun -sdk iphoneos clang' --as='gas-preprocessor.pl -arch aarch64 -- xcrun -sdk iphoneos clang' --extra-cflags='-arch arm64 -mios-version-min=13.0 -I/Users/changbeomahn/Projects/FFmpeg-iOS/build/install/FFmpeg/arm64/include' --extra-ldflags='-arch arm64 -mios-version-min=13.0 -L/Users/changbeomahn/Projects/FFmpeg-iOS/build/install/FFmpeg/arm64/lib'
HookMain: setjmp=0
FFmpeg_exit=1, will longjmp
HookMain: setjmp=1
libavutil 58. 3.100 / 58. 3.100
libavcodec 60. 6.100 / 60. 6.100
libavformat 60. 4.100 / 60. 4.100
libavdevice 60. 2.100 / 60. 2.100
libavfilter 9. 4.100 / 9. 4.100
libswscale 7. 2.100 / 7. 2.100
libswresample 4. 11.100 / 4. 11.100
file:///var/mobile/tmp/com.apple.WorkflowKit.BackgroundShortcutRunner/IMG_2751.mov: Operation not permitted
The issue is in the last line: Operation not permitted
I also tried just writing a file to the same directory as the media file:
let str = "Super long string here"
let filename = media.fileURL!.absoluteString.replacingOccurrences(of: media.filename, with: "asd.txt")
do {
try str.write(to: URL(string: filename)!, atomically: true, encoding: String.Encoding.utf8)
} catch {
print(error)
}
But got the error:
Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “asd.txt” in the folder “com.apple.WorkflowKit.BackgroundShortcutRunner”." UserInfo={NSFilePath=/var/mobile/tmp/com.apple.WorkflowKit.BackgroundShortcutRunner/asd.txt, NSUnderlyingError=0x280f09aa0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}
Apparently there is a permission issue, I tried googling about "AppIntents file permissions"/"shortcut permissions"/etc but found nothing. Im not a mobile developer so Im totally clueless. The same code though works fine in the simulator, it gets the permission issue only on device.