Objective-c iOS Unable to Share NSURL and NSString simultaneously to iMessage app

Is it possible to share NSURL and NString at the same time using the UIActivityViewController? I know it's possible using the MFMessageComposeViewController but wanted to use the native UI sheet so the user can select a different app if they wanted.

In this example, the filePath variable is a path to a video file saved on the device.

NSMutableArray *items = [NSMutableArray new];
[items addObject:[NSURL fileURLWithPath:filePath]];
UIViewController *rootViewController = UnityGetGLViewController();
UIActivityViewController *activity = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
[rootViewController presentViewController:activity animated:YES completion:nil];

Updating the items with an additional string value will result in only the video being shared.

NSMutableArray *items = [NSMutableArray new];
[items addObject:[NSURL fileURLWithPath:filePath]];
[items addObject:[NSString stringWithUTF8String:"Check out this video!"]];
UIViewController *rootViewController = UnityGetGLViewController();
UIActivityViewController *activity = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
[rootViewController presentViewController:activity animated:YES completion:nil];

The "Check out this video!" text is never included in the iMessage app.

Is this something that is possible? If not It would be nice to see some official Apple documentation about this. Also, this would be quite surprising considering iMessage is a built-in app, you would imagine it would have this capability.

Replies

I think your code is correct.

The "Check out this video!" text is never included in the iMessage app.

I think that's probably a feature of iMessage. The items you add are probably interpreted as alternatives, i.e. like the text/plain and text/html content in typical emails; it will choose one of the alternatives to use, whichever is "best" in some sense.

I'm not entirely sure about this though - I have more experience with the clipboard API, which is similar.

Put the URL in the string as a formatted string?