Post

Replies

Boosts

Views

Activity

Reply to How to get the AVCam demo app to work under Mac Catalyst?
Overdue update - The AVCam demo now runs under Mac Catalyst. Much of AVFoundation has been supported since Mac Catalyst 14.0. The AVCam demo needs a few small changes to build for Mac Catalyst. By default, the project is not setup with a Mac Catalyst destination. It only supports iPad apps running on Apple Silicon. Delete the "Mac (Designed for iPad)" destination and add the "Mac (Mac Catalyst)" destination. You may also have to change the macOS Deployment target in the Build Settings depending on the version of macOS running on your Mac. Thanks Apple for adding support for AVFoundation. Now I just need to figure out if I can support Camera Continuity under Mac Catalyst.
Topic: App & System Services SubTopic: General Tags:
May ’23
Reply to How to modify context menu shown in a UITextView?
I recently figured out a way to remove the "Show Fonts" and "Show Colors" menus from the context menu of a UITextView. This only works on iOS 16.0/Mac Catalyst 16.0 or later. The following is my Objective-C code. Should be easy enough to translate to Swift. I started by adding new method to UIMenu: Category declaration: @interface UIMenu (Additions) - (UIMenu *)menuByRemovingChildWithAction:(SEL)action; @end Category implementation: @implementation UIMenu (Additions) - (UIMenu *)menuByRemovingChildWithAction:(SEL)action { NSArray<UIMenuElement *> *children = self.children; for (NSInteger i = 0; i < children.count; i++) { UIMenuElement *element = children[i]; if ([element isKindOfClass:[UICommand class]]) { UICommand *cmd = (UICommand *)element; if (cmd.action == action) { NSMutableArray *newChildren = [children mutableCopy]; [newChildren removeObjectAtIndex:i]; if (newChildren.count == 0) { return nil; } else { return [self menuByReplacingChildren:newChildren]; } } } else if ([element isKindOfClass:[UIMenu class]]) { UIMenu *menu = (UIMenu *)element; UIMenu *newMenu = [menu menuByRemovingChildWithAction:action]; if (newMenu == nil) { NSMutableArray *newChildren = [children mutableCopy]; [newChildren removeObjectAtIndex:i]; return [self menuByReplacingChildren:newChildren]; } else if (newMenu != menu) { NSMutableArray *newChildren = [children mutableCopy]; newChildren[i] = newMenu; return [self menuByReplacingChildren:newChildren]; } } } return self; } @end This recursively goes through a menu hierarchy and removes any menu item that is a UICommand with the given action. With that in place you need to implement the iOS 16.0 UITextViewDelegate method: - (UIMenu *)textView:(UITextView *)textView editMenuForTextInRange:(NSRange)range suggestedActions:(NSArray<UIMenuElement *> *)suggestedActions API_AVAILABLE(ios(16.0)) { UIMenu *menu = [UIMenu menuWithChildren:suggestedActions]; menu = [menu menuByRemovingChildWithAction:NSSelectorFromString(@"toggleFontPanel:")]; menu = [menu menuByRemovingChildWithAction:NSSelectorFromString(@"orderFrontColorPanel:")]; return menu; } That's it. All other attempts failed. I was able to disable the "Show Fonts" menu by overriding canPerformAction:sender: in the App Delegate. But for some reason it did nothing for the "Show Colors" menu. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { if (action == NSSelectorFromString(@"toggleFontPanel:") || action == NSSelectorFromString(@"orderFrontColorPanel:")) { return NO; } BOOL res = [super canPerformAction:action withSender:sender]; return res; }
Topic: App & System Services SubTopic: General Tags:
May ’23
Reply to NSKeyedUnarchiver validateAllowedClass error
When debugging a message such as: [general] *** -[NSKeyedUnarchiver validateAllowedClass:forKey:] allowed unarchiving safe plist type ''NSNumber' (0x205da88f8) [/System/Library/Frameworks/Foundation.framework]' for key 'NS.objects', even though it was not explicitly included in the client allowed classes set: '{(     "'NSDictionary' (0x205da1178) [/System/Library/Frameworks/CoreFoundation.framework]",     "'NSString' (0x205da8948) [/System/Library/Frameworks/Foundation.framework]" )}'. This will be disallowed in the future. you want to look for a use of NSKeyedUnarchiver where you only list NSDictionary and NSString. Then you want to add NSNumber. Do not add NSObject.
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’22
Reply to Xcode 14 failed to prepare iOS 15.7 device?
Same issue but on an Intel MacBook Pro running macOS 12.6. One would have hoped that today's Xcode 14 would support all of the versions of iOS and iPadOS also released today. Oh well. I guess we all need to wait for Xcode 14.0.1 or something. Can't wait to download yet another 7+GB Xcode release on my 10Mbps Internet connection.
Sep ’22
Reply to How do I store FileManager.ubiquityIdentityToken?
I was dealing with this same issue in some older Objective-C code I was trying to update. After lots of different attempts I found the following solution (Swift version): if let token = FileManager.default.ubiquityIdentityToken {     do {         let data = try NSKeyedArchiver.archivedData(withRootObject: token, requiringSecureCoding: true)         if let newToken = try NSKeyedUnarchiver.unarchivedObject(ofClass: NSData.self, from: data) {             print("We got the token")             if newToken.isEqual(token) {                 print("tokens match")             } else {                 print("tokens do not match")             }         }     } catch {         print("oops: ", error)     } } This works and it compiles cleanly. But I'm worried that passing in NSData.self could possibly fail in some future implementation if Apple changes how the token is encoded.
Topic: App & System Services SubTopic: General Tags:
Jul ’22
Reply to How to change the app name shown in a Catalyst app?
So it seems that the name of the app shown in a Mac Catalyst app comes from the "Product Name" build setting for your target. I changed that from MyCoolApp to My Cool App and I started seeing the results I wanted. I find it odd that the app display name comes from the resulting .app name and the executable name and not the "Bundle display name" from Info.plist. Maybe this will help someone else.
Topic: App & System Services SubTopic: General Tags:
Jan ’21