Now that live previews are available in UIKit (source: https://developer.apple.com/wwdc23/10252)
I was wondering how to get a UIViewController from Objective-C. The Swift macro looks like this:
#Preview {
var controller = SomeViewController()
return controller;
}
Is there a way to get a live preview for UIViewControllers/UIViews written in Objective-C (other than wrapping it as a child view controller in an empty swift view controller)?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Okay so I'm getting this log every time I present a UIAlertController:
Mac Catalyst: Presenting view controller <UIAlertController: 0x10f027000> from detached view controller <MyViewController: 0x10d104080> is not supported, and may result in incorrect safe area insets and a corrupt root presentation. Make sure <MyViewController: 0x10d104080> is in the view controller hierarchy before presenting from it. Will become a hard exception in a future release.
A few points:
MyViewController is not detached and the presentation shows just fine.
I specifically check for this before presenting the alert controller like so:
BOOL okayToPresentError = (self.isViewLoaded
&& self.view.window != nil);
if (okayToPresentError)
{
[self presentErrorInAlertController:error];
}
else
{
//Wait until view did appear.
self.errorToPresentInViewDidAppear = error;
}
It spews out every time an error is fed back to my app and I present the alert controller (I can turn off the network connection and I show an alert controller with a "retry" button in it which will loop the error back so I can replay the error alert presentation over and over again) .
Every time the alert controller is presented, I get this spewing in the console. Please don't start throwing hard exceptions because the check is faulty.
I have a WKWebView that sets the UIDelegate:
self.webView.UIDelegate = self;
The following methods are never called when I right click in the WKWebView to being up a context menu:
-(void)webView:(WKWebView*)webView
contextMenuForElement:(WKContextMenuElementInfo*)elementInfo
willCommitWithAnimator:(id <UIContextMenuInteractionCommitAnimating>)animator
-(void)webView:(WKWebView*)webView
contextMenuConfigurationForElement:(WKContextMenuElementInfo*)elementInfo
completionHandler:(void (^)(UIContextMenuConfiguration * _Nullable configuration))completionHandler
- (void)webView:(WKWebView *)webView contextMenuDidEndForElement:(WKContextMenuElementInfo *)elementInfo;
This is from a Mac Catalyst app (I'm on macOS 14.0 23A344)
So I have a WKWebView with a loaded page. This page is playing an embedded Youtube video. The playback state is WKMediaPlaybackStatePlaying. All good.
Then I click a link on the page (navigation jumps to a new page) and the video is no longer playing. No video or audio. The navigationDelegate calls -webView:didFinishNavigation:
And my navigationDelegate call -requestMediaPlaybackStateWithCompletionHandler: on the webview from within -webView:didFinishNavigation:
And in the completion handler of -requestMediaPlaybackStateWithCompletionHandler: the playback state is WKMediaPlaybackStatePlaying but nothing is playing because we are on a new page....
I even tried calling -requestMediaPlaybackStateWithCompletionHandler: after a delay but that doesn't seem to make a difference (even gave it a delay as long as 5 seconds)
I tried redeeming a promo code for a subscription on iOS 18.
It's a yearly subscription (the promo code is for myself in this case). This always worked before. Now on iOS 18 when I redeem the code in the App Store it just spins an activity indicator in the navigation bar for a few seconds and stops. Promo code doesn't redeem. No error message either.
Now when I try to redeem the promo code on the Mac App Store I get the following error: "You must redeem this code on a device that supports App name". This error makes sense because the app is iOS/iPadOS only. But the fact that the Mac App Store displays the App name in the error message indicates that the code is valid and should work on iOS, but it does not.
So I'm using AVAudioEngine. When playing audio I become the 'now playing' app using MPNowPlayingInfoCenter/MPRemoteCommandCenter APIs.
When configuring MPRemoteCommandCenter I add a play/pause command target via -addTargetWithHandler on the togglePlayPauseCommand property.
Now I also have a play/pause button in my app's UI. When I pause playback from my app's UI (which means I'm the active app, I'm in the foreground), what I do is this:
-I pause the AVAudioPlayerNode I'm using with AVAudioEngine.
I do not, stop, reset, etc. the AVAudioEngine. I only pause the player node. My thought process here is that the user just pressed pause and it is very likely that he will hit 'play' to resume playback in the near future because
My app is in the foreground and the user just hit the pause button.
Now if my app moves to the background and if I receive a memory warning I presume it'd make sense to tear down the engine or pause it. Perhaps I'm wrong about this?
So when I initially hit the play button from my app's UI I also activate my AVAudioSession. I do this in high priority NSOperation since the documentation warns that "we recommend that applications not activate their session from a thread where a long blocking operation will be problematic."
So now I'm playing and I hit pause from my app's UI. Then I quickly bring up the "Now Playing" center and I see I'm the "Now Playing" app but the play-pause button is showing the pause icon instead of the play icon but I'm in the pause state. I do set MPNowPlayingInfoCenter's playbackState to MPNowPlayingPlaybackStatePaused when I pause. Not surprisingly this doesn't work. The documentation states this is for macOS only.
So the only way to get MPRemoteCommandCenter to show the "play" image for the play-pause button is to deactivate my AVAudioSession when I pause playback? Since I change the active state of my audio session in a NSOperation because documentation recommends "we recommend that applications not activate their session from a thread where a long blocking operation will be problematic." the play-pause toggle in the remote command center won't immediately update since I'm doing it on another thread.
IMO it feels kind of inappropriate for a play-pause button to wait on a NSOperation activating the audio session before updating its UI when I already know my play/paused state, it should update right away like the button in my app does. Wouldn't it be nicer to just use MPNowPlayingInfoCenter's playbackState property on iOS too? If I'm no the longer the now playing app/active audio session it doesn't matter since I'm not in the now playing UI, just ignore it?
Also is it recommended that I deactivate my audio session explicitly every time the user pauses audio in my app (when I'm in the foreground)?
Also when I do deactivate the audio session I get an error: AVAudioSessionErrorCodeIsBusy (but the button in the now playing center updates to the proper image). I do this :
-(void)pause
{
[self.playerNode pause];
[self runOperationToDeactivateAudioSession];
// This does nothing on iOS:
MPNowPlayingInfoCenter *nowPlayingCenter = [MPNowPlayingInfoCenter defaultCenter];
nowPlayingCenter.playbackState = MPNowPlayingPlaybackStatePaused;
}
So in -runOperationToDeactivateAudioSession I get the AVAudioSessionErrorCodeIsBusy. According to the documentation
Starting in iOS 8, if the session has running I/Os at the time that deactivation is requested, the session will be deactivated, but the method will return NO and populate the NSError with the code property set to AVAudioSessionErrorCodeIsBusy to indicate the misuse of the API.
So pausing the player node when pausing isn't enough to meet the deactivation criteria. I guess I have to pause or stop the audio engine. I could probably wait until I receive a scene went to background notification or something before deactivating my audio session (which is async, so the button may not update to the correct image in time). This seems like a lot of code to have to write to get a play-pause toggle to update, especially in iPad-multi window scene environment.
What's the recommended approach?
Should I pause the AudioEngine instead of the player node always?
Should I always explicitly deactivate my audio session when the user pauses playback from my app's UI even if I'm in the foreground?
I personally like the idea of just being able to set
[MPNowPlayingInfoCenter defaultCenter].playbackState = MPNowPlayingPlaybackStatePaused;
But maybe that's because that would just make things easier on me. This does feels overcomplicated though. If anyone can share some tips on how I should handle this, I'd appreciate it.
I'm noticing some weird glitches with my collection view headers on macOS Tahoe.
The sections headers are pinned to the visible region. I headers fade out when scrolling and are supposed to fade back in but sometimes they don't fade back in and the header remains but the header text doesn't come back (until I scroll again).
How can I turn off this scroll animation thingy?
I have Mac apps that embed “Helper Apps” inside their main bundle. The helper apps do work on behalf of the main application.
The helper app doesn’t show a dock icon, it does show minimal UI like an open panel in certain situations (part of NSService implementation). And it does make use of the NSApplication lifecycle and auto quits after it completes all work.
Currently the helper app is inside the main app bundle at: /Contents/Applications/HelperApp.app
Prior to Tahoe these were never displayed to user in LaunchPad but now the Spotlight based AppLauncher displays them.
What’s the recommended way to get these out of the Spotlight App list on macOS Tahoe?
Thanks in advance.
Appkit starting logging these warnings in macOS 26.1 about my app's MainMenu.
**Internal inconsistency in menus - menu <NSMenu: 0xb91b2ff80>
Title: AppName
Supermenu: 0xb91a50b40 (Main Menu), autoenable: YES
Previous menu: 0x0 (None)
Next menu: 0x0 (None)
Items: ()
believes it has [<NSMenuSubclassHereThisIsTheMenuBarMenuForMyApp:] 0xb91a50b40>
Title: Main Menu
Supermenu: 0x0 (None), autoenable: YES
Previous menu: 0x0 (None)
Next menu: 0x0 (None)
Items: (
) as a supermenu, but the supermenu does not seem to have any item with that submenu
**
I don't what that means. The supermenu is the menu that represents the menu used for my app's menu bar (as described by NSMenuSubclassHereThisIsTheMenuBarMenuForMyApp
Everything seems to work fine but log looks scary. Please don't throw!
Returning to a Mac Catalyst app that I put to the side for awhile..when running it on Xcode 26.1 it crashes at launch with:
Assertion failure in -[NSToolbarItemGroupView _layoutWrapperViewsWithAttributes:], NSToolbarItemGroupView.m:599
No attributes were found for item
Call stack has a bunch of Autolayout code in AppKit like:
[NSWindow(NSConstraintBasedLayoutInternal) _layoutViewTree] + 120
50 AppKit 0x00000001911e8a10 -[NSWindow(NSConstraintBasedLayoutInternal) layoutIfNeeded] + 240
51 UIKitMacHelper 0x00000001a98f293c -[UINSWindow layoutIfNeeded] + 56
A few unnamed symbols mixed in maybe that's that Swiftness beneath the surface. App is just murdered on launch. I assume this is related to using NSToolbarItemGroup when building an NSToolbar...
I do see this log out:
NSToolbarItemGroup does not support selectionMode. Create the group with one of the class constructors to support selection.
Which is an interesting log so I commented out all calls to setSelectionMode: but still the same crash.
I do set the groups subitems property directly (I do not use the class constructors as the logging statement above indicates). I have no idea if using the class constructors will workaround this issue or not but I'm not particularly excited about that idea because I have items in the same toolbar group with different actions.
So to support Apple Silicon in my app I need a fat version OpenSSL for Intel/Arm.
However, I cannot get OpenSSL to build for ARM if I lower the deployment target to an earlier version of macOS before Big Sur.
I was able to make a fat version of OpenSSL by making the ARM half have a deployment target of 10.15, but when added to my project, Xcode spits out warnings about Object files built for a newer macOS version than being linked.
Anyone know the proper procedure to make a backward compatible version (pre-macOS 10.15) of OpenSSL static library and still support M1 natively?
I don't think I'm currently willing to raise the deployment target of my app to 10.15 just to link the OpenSSL library.
I now have an M1 Mac and an Intel Mac. I have an XCFramework that targets the iOS simulator and devices. My XCFramework works fine but I'd like to be able to run my app (which uses the XCFramework) on the iOS simulator on both my Macs (m1 & intel).
Now my M1 Mac complains about the x86_64 architecture when I try to run it on the simulator. So I rebuilt the XCFramework (recompiling the simulator version on the M1 Mac).
I'm compiling the source code from Terminal (building OpenSSL). There is no .xcarchive here. Anyway now the app runs on the simulator on the M1 Mac but on the Intel Mac it won't build (basically the same problem in reverse).
So... I made three versions of the library now (for iOS devices, iOS simulator on m1 Mac, and for the iOS simulator on Intel Macs). When I try to make an XCFramework to wrap all three static libraries I get the following error:
Both "ios-x86_64-simulator" and "ios-arm64-simulator" represent two equivalent library definitions.
I found another thread where the accepted answer was to lipo the x86_64 and arm simulators together, then build the xcframework. I've seen posts from Apple engineers that say using lipo is not supported (reference: https://developer.apple.com/forums/thread/709812?answerId=719667022#719667022 )
So where am I going wrong? I try to make the xcframework like so:
xcodebuild -create-xcframework
-library build/sim/openssl-1.1.1q/libcrypto.a -headers build/sim/openssl-1.1.1q/crypto
-library build/phones/openssl-1.1.1q/libcrypto.a -headers build/phones/openssl-1.1.1q/crypto
-library build/intelsim/openssl-1.1.1q/libcrypto.a -headers build/intelsim/openssl-1.1.1q/crypto
-output build/Crypto.xcframework
Topic:
App & System Services
SubTopic:
General
Tags:
Universal Apps
Simulator
Apple Silicon
Frameworks
I'm trying to figure out how I'm suppose to work with this API on UIFindSession:
- (void)performSearchWithQuery:(NSString *)query options:(nullable UITextSearchOptions *)options;
I want to provide a UITextSearchOptions object, but the properties are readonly so I'm not sure what purpose it serves exposing it in the public API?
@interface UITextSearchOptions : NSObject
/// See UITextSearchMatchMethod above.
@property (nonatomic, readonly) UITextSearchMatchMethod wordMatchMethod;
/// Comparison options to use when searching for strings.
@property (nonatomic, readonly) NSStringCompareOptions stringCompareOptions;
@end
So I can't simply invoke a search like this...which would've really been nice...
UIFindSession *session = findInterfaction.activeFindSession;
UITextSearchOptions *searchOptions = [[UITextSearchOptions alloc]init];
searchOptions.stringCompareOptions = NSCaseInsensitiveSearch; //readonly can't...
[session performSearchWithQuery:searchString options:searchOptions];
There is this API:
/// available in @c UITextSearchOptions, which can be either modified, augmented, or omitted.
@property (nonatomic, readwrite, copy, nullable) UIMenu *_Nullable (^optionsMenuProvider)(NSArray<UIMenuElement *> *defaultOptions);
So I can remove menu items that edit the UITextSearchOptions but how exactly do I "override" them for my needs?
I noticed a bug on rotation change in my app on iPhone 14 Pro Max simulator. Basically a view in my view hierarchy is hidden when it shouldn't be. In landscape mode there isn't enough room for this view so I hide it on the iPhone (not essential). But when tilting back to portrait mode I unhide it.
-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
BOOL isIPhone = UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone;
BOOL isIPhoneAndGoingLandscapeMode = (isIPhone
&& size.width > size.height);
if (isIPhoneAndGoingLandscapeMode)
{
self.someView.hidden = YES;
}
else
{
self.someView.hidden = NO;
}
}
So this view controller is presented modally (form sheet style).
On iPhone 14 Pro Max on orientation -viewWillTransitionToSize:withTransitionCoordinator: is called twice and the size parameter is always:
(CGSize) size = (width = 414, height = 394)
This is the sized passed to my app when rotating to portrait and landscape so my isIPhoneAndGoingLandscapeMode flag always is YES because 414 > 394. The 414 x 394 size appears to be false.
My view controller's view in landscape on iPhone 14 pro max logs out to:
(origin = (x = 0, y = 0), size = (width = 932, height = 430))
And 932 x 430 is the size I expected to be passed to me in -viewWillTransitionToSize:withTransitionCoordinator:
Unless I'm missing something can this behavior be explained?
I’m trying to migrate a custom UITableViewCell to use a content configuration so I can properly subclass the content view (setting a subclass on the content view in Interface Builder apparently is not supported).
So when I load up the cell and set the content configuration my console is flooded with these logs:
Warning: You are setting a new content configuration to a cell that has an existing content configuration, but the existing content view does not support the new configuration. This means the existing content view must be replaced with a new content view created from the new configuration, instead of updating the existing content view directly, which is expensive. Use separate reuse identifiers for different types of cells to avoid this. Make a symbolic breakpoint at UIContentConfigurationAlertForReplacedContentView to catch this in the debugger.
Cell: <MyCellSubclassHere: 0x15d0b5c00>
Existing content configuration: (null);
New content configuration: <MyCustomConfigurationHere: 0x6000034ad190>
As you can see the existing content configuration is nil. I tried setting my custom content configuration as early as possible (by overriding the designated initializer on UITableViewCell) as a workaround but that didn't work. Still console spew.
And by the time cellForRowAtindexPath: is called the content configuration is always nil and has to be rebuilt (apparently UIKit is setting it to nil in prepareForReuse?)
I also tried overriding -setContentConfiguration: to catch when the configuration is being set to nil but UIKit must be setting the ivar to nil directly, because the setter is never called with nil.
Anyone know of a workaround? I don't want to ship an app that constantly logs this out on scroll.
I opened FB11595949