I found that I can get occlusionState with the following code on both Catalyst and Mac (built for iPad).
I only tested this on MainStage.
The code is not tested on iOS/iPadOS devices.
#import "AudioUnitViewController.h"
#import "UnotoneAudioUnit.h"
#import <UIKit/UIKit.h>
@interface NSObject (DUMMY)
- (NSUInteger)occlusionState;
- (NSArray<UIWindow*>*)uiWindows;
@end
@interface AudioUnitViewController () <AUAudioUnitFactory>
@end
@implementation AudioUnitViewController
- (AUAudioUnit *)createAudioUnitWithComponentDescription:(AudioComponentDescription)desc error:(NSError **)error {
self.audioUnit = [[UnotoneAudioUnit alloc] initWithComponentDescription:desc error:error];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"NSWindowDidChangeOcclusionStateNotification" object:nil];
return self.audioUnit;
}
- (void)handleNotification:(NSNotification *)note
{
id uinswindow = note.object;
if ([uinswindow respondsToSelector:@selector(occlusionState)] &&
[uinswindow respondsToSelector:@selector(uiWindows)]) {
UIWindow *window = self.view.window;
NSArray <UIWindow *> *windows = [uinswindow uiWindows];
if ([windows containsObject:window]) {
NSUInteger state = [uinswindow occlusionState];
NSLog(@"OcclusionState: %ld", state); // bit 1 (1UL<<1) is the visible flag.
}
}
}
@end
Post
Replies
Boosts
Views
Activity
I have experienced the same thing, past and present.
In June 2023, it used to take about a week to redeem the code in Japan.
And now, I'm experiencing the same thing again. I hope I can redeem the code soon.
The reason codes have been updated.
1C8F.1
Declare this reason to access user defaults to read and write information that is only accessible to the apps, app extensions, and App Clips that are members of the same App Group as the app itself.
This reason does not permit reading information that was written by apps, app extensions, or App Clips outside the same App Group or by the system. This reason also does not permit writing information that can be accessed by apps, app extensions, or App Clips outside the same App Group.
https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_use_of_required_reason_api
Thank you, Apple.
I hope Xcode will be fixed. The ld_prime has the problem.
@galad87 Thank you.
I added "-ld_classic" to other linker flags and the app doesn't crash on iOS 12.
Error is that:
Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)
Xcode Version 15.0.1 (15A507), iPad mini 3, iOS 12.5.7 (16H81)
It crashes at an inline function.
template <class _Tp>
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _LIBCPP_DEPRECATED_IN_CXX17
pair<_Tp*, ptrdiff_t>
get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
crash at iPhoneOS17.0.sdk/usr/include/c++/v1/__memory/temprary_buffer.h:46
__r.first = static_cast<_Tp*>(::operator new(
__n * sizeof(_Tp), nothrow));
call back trace:
Thread 1 Queue : com.apple.main-thread (serial)
#0 0x0000000000000000 in 0x00000000 ()
#1 0x000000010096df10 in std::__1::pair<std::__1::tuple<unsigned long, unsigned long long*>*, long> std::__1::get_temporary_buffer[abi:v160006]<std::__1::tuple<unsigned long, unsigned long long*>>(long) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.0.sdk/usr/include/c++/v1/__memory/temporary_buffer.h:46
#2 0x000000010096dd58 in void std::__1::__stable_sort_impl[abi:v160006]<std::__1::_ClassicAlgPolicy, std::__1::__wrap_iter<std::__1::tuple<unsigned long, unsigned long long*>*>, execute_tests::$_0>(std::__1::__wrap_iter<std::__1::tuple<unsigned long, unsigned long long*>*>, std::__1::__wrap_iter<std::__1::tuple<unsigned long, unsigned long long*>*>, execute_tests::$_0&) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.0.sdk/usr/include/c++/v1/__algorithm/stable_sort.h:225
#3 0x000000010096c2a4 in void std::__1::stable_sort[abi:v160006]<std::__1::__wrap_iter<std::__1::tuple<unsigned long, unsigned long long*>*>, execute_tests::$_0>(std::__1::__wrap_iter<std::__1::tuple<unsigned long, unsigned long long*>*>, std::__1::__wrap_iter<std::__1::tuple<unsigned long, unsigned long long*>*>, execute_tests::$_0) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.0.sdk/usr/include/c++/v1/__algorithm/stable_sort.h:236
#4 0x000000010096c110 in ::execute_tests() at /System/Volumes/Data/Developer/codes/test5/test5/Tests.cpp:19
#5 0x0000000100971b00 in -[AppDelegate application:didFinishLaunchingWithOptions:] at /System/Volumes/Data/Developer/codes/test5/test5/AppDelegate.m:21
#6 0x0000000256eca0f0 in -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] ()
#7 0x0000000256ecb854 in -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] ()
#8 0x0000000256ed0fe0 in -[UIApplication _runWithMainScene:transitionContext:completion:] ()
#9 0x00000002567942a4 in __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke ()
#10 0x000000025679c83c in +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] ()
#11 0x0000000256793f28 in -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] ()
#12 0x0000000256794818 in -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] ()
#13 0x0000000256792b64 in __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke ()
#14 0x000000025679282c in -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] ()
#15 0x000000025679736c in __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke ()
#16 0x0000000256798150 in _performActionsWithDelayForTransitionContext ()
#17 0x0000000256797224 in -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] ()
#18 0x000000025679bf24 in -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] ()
#19 0x0000000256ecf5e8 in -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] ()
#20 0x0000000256acbe04 in -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] ()
#21 0x000000022d1d39fc in -[FBSSceneImpl _didCreateWithTransitionContext:completion:] ()
#22 0x000000022d1dd40c in __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 ()
#23 0x000000022d1dcc14 in __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke ()
#24 0x0000000100cf0c78 in _dispatch_client_callout ()
#25 0x0000000100cf4840 in _dispatch_block_invoke_direct ()
#26 0x000000022d20e040 in __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ ()
#27 0x000000022d20dcdc in -[FBSSerialQueue _performNext] ()
#28 0x000000022d20e294 in -[FBSSerialQueue _performNextFromRunLoopSource] ()
#29 0x000000022a7e7f1c in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#30 0x000000022a7e7e9c in __CFRunLoopDoSource0 ()
#31 0x000000022a7e7784 in __CFRunLoopDoSources0 ()
#32 0x000000022a7e26c0 in __CFRunLoopRun ()
#33 0x000000022a7e1fb4 in CFRunLoopRunSpecific ()
#34 0x000000022c9e479c in GSEventRunModal ()
#35 0x0000000256ed2c38 in UIApplicationMain ()
#36 0x0000000100971ba8 in main at /System/Volumes/Data/Developer/codes/test5/test5/main.m:17
I decided to downgrade to Xcode 15.0 because I could not wait any longer.
It works.
+1.
Yesterday I successfully submitted my app to TestFlight public beta, today I failed.
I forgot setting delegate. but the issue still occurs.
- (IBAction)trigger:(id)sender
{
UIDocumentPickerViewController *picker = [[UIDocumentPickerViewController alloc] initForOpeningContentTypes:@[UTTypeData] asCopy:NO];
picker.delegate = self;
picker.directoryURL = directoryURL;
[self presentViewController:picker animated:YES completion:nil];
}
I found a workaround.
Put this code in your ViewController.
// becomeFirstResponder returns "NO" in "viewDidLoad".
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self becomeFirstResponder];
}
- (BOOL)canBecomeFirstResponder
{
return YES;
}
- (UIEditingInteractionConfiguration)editingInteractionConfiguration
{
return UIEditingInteractionConfigurationNone;
}
If you implement Keyboard Input, this should be in the UIResponder object.