macOS Catalyst UIActivityViewController Add to photos exception

When I try to share image on macOS Catalyst with UIActivityViewController and selecting Add to photos:


1) Photo is actually added to photos

2) Immediately after I get Exception (and after that nothing from share menu works):


[xpc.exceptions] <NSXPCConnection: 0x6000030222e0> connection to service on pid 26282 named com.apple.share.System.add-to-iphoto.apple-extension-service: Exception caught during decoding of received selector _completeRequestReturningItems:forExtensionContextWithUUID:completion:, dropping incoming message.

Exception: Exception while decoding argument 0 (#2 of invocation):

Exception: value for key 'NS.objects' was of unexpected class 'NSURL'. Allowed classes are '{(

NSDate,

NSNumber,

NSData,

NSDictionary,

NSArray,

NSString

)}'


I have no idea how to fix this?

Replies

I'm seeing the exact same issue and errors. Once the error happens, even selecting on the "More" option of the activity view doesn't do anything.


Restarting the app gets the activity view working again.


Time to file a bug report.

Anything new about this? The same issue happens with Xcode 11.2.

****.

This will require a macOS update to fix the problem. Xcode can't fix this. File a bug report if you have not done so already. File a bug report for every single [Catalyst] issue you run into.

//fix mac catalyst bug: UIActivityViewController add image to photo
@interface NSObject (FixCatalystBug)

@end

@implementation NSObject  (FixCatalystBug)

+ (void)load{
    Class cls = NSClassFromString(@"NSXPCDecoder");
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
      
        SEL selectors[] = {
            #pragma clang diagnostic push
            #pragma clang diagnostic ignored "-Wundeclared-selector"
            @selector(_validateAllowedClass:forKey:allowingInvocations:)
            #pragma clang diagnostic pop
        };
      
        for (NSUInteger index = 0; index < sizeof(selectors) / sizeof(SEL); ++index) {
            SEL originalSel = selectors[index];
            SEL swizzledSel = NSSelectorFromString([@"fs_swizzled_" stringByAppendingString:NSStringFromSelector(originalSel)]);
            [cls fs_exchangeImpWithOriginalSel:originalSel swizzledSel:swizzledSel];
        }
    });
}

- (BOOL)fs_swizzled__validateAllowedClass:(Class)cls forKey:(id)key allowingInvocations:(id)allowingInvocations{
    BOOL _validate = NO;
    @try {
        _validate = [self fs_swizzled__validateAllowedClass:cls forKey:key allowingInvocations:allowingInvocations];
    } @catch (NSException *exception) {
        if ([key isEqualToString:@"NS.objects"] && [cls isKindOfClass:[NSURL class]]) {
            _validate = YES;
        }
    }
    return _validate;
}

@end
#endif