I’d appreciate some help in diagnosing a crash in MPMediaLibrary that occurs on some iOS 15.1.x user devices. So far this issue can't be reproduced with test devices that range from iOS10 to iOS15.2, whether via Xcode 12.4 or TestFlight.
The app needs access to the device’s microphone and audio files which are selected via the MPMediaPickerController. The usual usage description keys (namely NSMicrophoneUsageDescription, NSAppleMusicUsageDescription and kTCCServiceMediaLibrary) are specified in the info.plist.
The crash relates to library access and involves the iTunesCloud binary. The crash occurs when the app starts, probably for the first time after installation (not the best way to greet new users).
Here is a sample crash report:
Here is a typical traceback:
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x00000001b8964504 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x00000001b8964b9c mach_msg + 76 (mach_msg.c:119)
2 libdispatch.dylib 0x000000018165227c _dispatch_mach_send_and_wait_for_reply + 520 (mach.c:815)
3 libdispatch.dylib 0x000000018165262c dispatch_mach_send_with_result_and_wait_for_reply + 56 (mach.c:2019)
4 libxpc.dylib 0x00000001f2576b9c xpc_connection_send_message_with_reply_sync + 240 (connection.c:974)
5 TCC 0x00000001e961c0c0 tccd_send_message + 940 (TCC.c:490)
6 TCC 0x00000001e9621e08 __TCCAccessRequest_block_invoke.213 + 876 (TCC.c:591)
7 libdispatch.dylib 0x0000000181637660 _dispatch_client_callout + 20 (object.m:560)
8 libdispatch.dylib 0x00000001816468b4 _dispatch_lane_barrier_sync_invoke_and_complete + 56 (queue.c:1016)
9 libsystem_trace.dylib 0x000000019c147668 _os_activity_initiate_impl + 64 (activity.c:131)
10 TCC 0x00000001e961d4e0 TCCAccessRequest + 476 (TCC.c:1019)
11 TCC 0x00000001e961c73c TCCAccessPreflight + 300 (TCC.c:1651)
12 iTunesCloud 0x0000000198d58160 -[ICCloudServiceStatusMonitor authorizationStatusForScopes:] + 60 (ICCloudServiceStatusMonitor.m:689)
13 MediaPlayer 0x000000018a8c8ee4 +[MPMediaLibrary authorizationStatus] + 64 (MPMediaLibrary.m:778)
16 MyAppppp 0x00000001003e9880 AppDelegate.application(_:willFinishLaunchingWithOptions:) + 32 (AppDelegate.swift:23)
17 MyAppppp 0x00000001003e9880 @objc AppDelegate.application(_:willFinishLaunchingWithOptions:) + 136 (<compiler-generated>:20)
The app startup logic is basically:
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool
{
let audioSession = AVAudioSession.sharedInstance()
if audioSession.recordPermission == .undetermined
{
audioSession.requestRecordPermission
{
// Permission initialized
}
}
if MPMediaLibrary.authorizationStatus() == .notDetermined // Sometimes crashes in iOS15.1 on user devices
{
MPMediaLibrary.requestAuthorization
{
// Permission initialized
}
}
if MPMediaLibrary.authorizationStatus() == .authorized
{
// The following code sometimes crashes in iOS15.1 on user devices without the enclosing ".authorized” check
let predicate = MPMediaPropertyPredicate(value: defaultSongId, forProperty: MPMediaItemPropertyPersistentID)
let query = MPMediaQuery()
}
return true
}
Questions:
- What exactly is the iTunesCloud binary doing? Is additional configuration needed?
- Why does the crash happen only on some iOS 15.1 user devices?
- Is it too early in the app lifecycle to call MPMediaLibrary.authorizationStatus?
- Post-crash workaround: Are users able to grant access to the library via the device’s global privacy settings?
Thanks!