iOS 15.1 Crash: MPMediaLibrary.authorizationStatus

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:

  1. What exactly is the iTunesCloud binary doing? Is additional configuration needed?
  2. Why does the crash happen only on some iOS 15.1 user devices?
  3. Is it too early in the app lifecycle to call MPMediaLibrary.authorizationStatus?
  4. Post-crash workaround: Are users able to grant access to the library via the device’s global privacy settings?

Thanks!

  • I am seeing the same callstack being reported when calling AVCaptureDevice.authorizationStatus(for: AVMediaType.video).

  • @Spads: At what point in the app’s lifecycle do you call authorizationStatus? Which devices are crashing?

  • Update: Number of crashes relative to new installations: iOS 15.1: 64%. No crashes for iOS 15.0 and 14.x. This is a real problem. Most 15.1 users have deleted the app.

Add a Comment

Replies

@codec Have you any success with solving this problem?

I have the same problems with [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; & [PHPhotoLibrary authorizationStatusForAccessLevel:PHAccessLevelReadWrite];

  • @mamikon13: No answers yet. 

    In response to my TSI request, Apple DTS said to follow up with them if the issue persists.

    Are you seeing any crashes in iOS 15.2 or 14.x? At what point in the app’s lifecycle do you call authorizationStatus?

Add a Comment

I see crashes for iOS > 15.0 related to different accesses I mentioned above. I present some viewController on the app start and all of that happened in viewDidLoad. Also some crashes occur in the didSelectItemAtIndexPath method

  • @mamikon13: Two more questions: 1> Can you reproduce the crashes on your test device? 2> Do you call authorizationStatus after application(_:didFinishLaunchingWithOptions:) has executed?

  • @codec: 1 - No; 2 - yes, such cases also exist. Also got it by observing UIApplicationWillEnterForegroundNotification

    Also I get crashes on iOS 14

Add a Comment