'UIActivityViewController and presentViewController generating numerous errors

I recently came encountered an error with UIActivityViewController in developing in objective-c running under IOS 15.4.1 that used to work. In fact, I copied the below code form one app (where it worked) to another (where it stopped working) generating a number of errors below. On a physical device, the activity controller (for airdrop and others) pops up and then immediately pops down when these errors appear with no chance to interact. There are no issues on the Xcode Simulator and it works fine. Any suggestions would be appreciated.

-- Objective-C Code --

// create a message

NSString *theMessage = @"Some text we're sharing with an activity controller";

NSArray *items = @[theMessage];

// build an activity view controller

UIActivityViewController *controller = [[UIActivityViewController alloc]initWithActivityItems:items applicationActivities:nil];

// and present it

[self presentViewController:controller animated:NO completion:^{

--- Error Log ---

2022-04-21 14:01:53.986049-0400 myapp[29328:1429870] shareText Some text we're sharing with an activity controller 2022-04-21 14:01:54.149992-0400 myapp[29328:1429870] [Default] Task myapp[29328]/1#4 LF=0 couldn't find entitlement CopresenceCore.Entitlement.publicAPI error nil 2022-04-21 14:01:54.410315-0400 myapp[29328:1429870] [Default] Task myapp[29328]/1#4 LF=0 couldn't find entitlement CopresenceCore.Entitlement.publicAPI error nil 2022-04-21 14:01:54.587110-0400 myapp[29328:1429870] [default] LaunchServices: store (null) or url (null) was nil: Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]} 2022-04-21 14:01:54.587209-0400 myapp[29328:1429870] [default] Attempt to map database failed: permission was denied. This attempt will not be retried. 2022-04-21 14:01:54.587282-0400 myapp[29328:1429870] [db] Failed to initialize client context with error Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]} 2022-04-21 14:01:54.620054-0400 myapp[29328:1429870] [default] -imageForImageDescriptor: can do IO please adopt -imageForDescriptor: for IO free drawing or -prepareImageForDescriptor: if IO is allowed. (This will become a fault soon.) 2022-04-21 14:01:54.631883-0400 myapp[29328:1429870] [LayoutConstraints] Changing the translatesAutoresizingMaskIntoConstraints property of a UICollectionReusableView that is managed by a UICollectionView is not supported, and will result in incorrect self-sizing. View: <_UIActivityContentFooterView: 0x1091b0670; baseClass = UICollectionReusableView; frame = (20 288; 374 52); layer = <CALayer: 0x2813a09c0>> 2022-04-21 14:01:54.647215-0400 myapp[29328:1429870] [default] LaunchServices: store (null) or url (null) was nil: Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]} 2022-04-21 14:01:54.647308-0400 myapp[29328:1429870] [default] Attempt to map database failed: permission was denied. This attempt will not be retried. 2022-04-21 14:01:54.647381-0400 myapp[29328:1429870] [db] Failed to initialize client context with error Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]} 2022-04-21 14:01:54.647627-0400 myapp[29328:1429870] [default] -imageForImageDescriptor: can do IO please adopt -imageForDescriptor: for IO free drawing or -prepareImageForDescriptor: if IO is allowed. (This will become a fault soon.) 2022-04-21 14:01:55.226089-0400 myapp[29328:1429870] shareText: presentViewController completed 2022-04-21 14:01:55.761911-0400 myapp[29328:1430040] [ShareSheet] connection invalidated



Solution 1:[1]

The cause of this problem was that after displaying the ActivityViewController in one code execution thread, another thread in the same app was dismissing the ActivityViewController.

I found the issue by setting a symbolic breakpoint at -[UIViewController dismissViewControllerWithTransition:completion:] and then examining the stack trace to find which thread was dismissing the ActivityViewController.

What was confusing was there are still error messages in the console but these are unrelated to the problem. By looking at other message posts, this seems to be log noise and to ignore it. Example of these error messages are: "Attempt to map database failed: permission was denied. This attempt will not be retried." or "-imageForImageDescriptor: can do IO please adopt -imageForDescriptor: for IO free drawing or -prepareImageForDescriptor: if IO is allowed. (This will become a fault soon.)"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1