I have the same issue. I am on Ventura 13.0.1 and Xcode 14.2. The sample code works for me when I use a simulator on iOS 15.5, but on iOS 16.2, it crashes immediately on NISession(). Here's my error stack:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libdispatch.dylib 0x180137a70 _dispatch_assert_queue_fail + 116
1 libdispatch.dylib 0x180137a68 _dispatch_assert_queue_fail + 108
2 libdispatch.dylib 0x1801379fc dispatch_assert_queue + 188
3 NearbyInteraction 0x102f92e64 -[NIServerConnection activate:] + 80
4 NearbyInteraction 0x102f7c030 -[NISession _activateSyncWithTimeout:] + 204
5 NearbyInteraction 0x102f7a4ec -[NISession _initAndConnectToServerWithOptions:] + 620
6 NearbyInteraction 0x102f7b380 -[NISession init] + 16
7 proximity 0x102aecac4 @nonobjc NISession.init() + 24
8 proximity 0x102ae58c4 NISession.__allocating_init() + 32
9 proximity 0x102ae5414 ViewController.startup() + 84 (ViewController.swift:73)
10 proximity 0x102ae4d00 ViewController.viewDidLoad() + 1392 (ViewController.swift:58)
11 proximity 0x102ae4d90 @objc ViewController.viewDidLoad() + 36
12 UIKitCore 0x109b041d8 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 80
13 UIKitCore 0x109b07f00 -[UIViewController loadViewIfRequired] + 708
14 UIKitCore 0x109b081ec -[UIViewController view] + 20
15 UIKitCore 0x10a1c9b28 -[UIWindow addRootViewControllerViewIfPossible] + 132
16 UIKitCore 0x10a1c9564 -[UIWindow _updateLayerOrderingAndSetLayerHidden:actionBlock:] + 212
17 UIKitCore 0x10a1ca39c -[UIWindow _setHidden:forced:] + 228
18 UIKit 0x1047d538c -[UIWindowAccessibility _orderFrontWithoutMakingKey] + 88
19 UIKitCore 0x10a1d8f08 -[UIWindow _mainQueue_makeKeyAndVisible] + 36
20 UIKitCore 0x10a3c3040 -[UIWindowScene _performDeferredInitialWindowUpdateForConnection] + 204
21 UIKitCore 0x10976ea8c +[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] + 1096
22 UIKitCore 0x10a1937f8 -[UIApplication _connectUISceneFromFBSScene:transitionContext:] + 884
23 UIKitCore 0x10a193c80 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 368
24 UIKitCore 0x109cfc9bc -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 260
25 FrontBoardServices 0x184ef7868 -[FBSScene _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 316
26 FrontBoardServices 0x184f1df68 __92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke.59 + 92
27 FrontBoardServices 0x184f03350 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 160
28 FrontBoardServices 0x184f1dbf0 __92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke + 296
29 libdispatch.dylib 0x180135768 _dispatch_client_callout + 16
30 libdispatch.dylib 0x1801396a4 dispatch_block_invoke_direct + 376
31 FrontBoardServices 0x184f3d44c FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 44
32 FrontBoardServices 0x184f3d340 -[FBSSerialQueue targetQueue_performNextIfPossible] + 176
33 FrontBoardServices 0x184f3d480 -[FBSSerialQueue performNextFromRunLoopSource] + 24
34 CoreFoundation 0x18037318c CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 24
35 CoreFoundation 0x1803730d4 __CFRunLoopDoSource0 + 172
36 CoreFoundation 0x18037289c __CFRunLoopDoSources0 + 320
37 CoreFoundation 0x18036ceb0 __CFRunLoopRun + 756
38 CoreFoundation 0x18036c7a4 CFRunLoopRunSpecific + 584
39 GraphicsServices 0x188ff7c98 GSEventRunModal + 160
40 UIKitCore 0x10a19237c -[UIApplication run] + 868
41 UIKitCore 0x10a196374 UIApplicationMain + 124
42 libswiftUIKit.dylib 0x1032acfd0 UIApplicationMain(::::) + 100
43 proximity 0x102aed328 static UIApplicationDelegate.main() + 104
44 proximity 0x102aed2b0 static AppDelegate.$main() + 44 (AppDelegate.swift:10)
45 proximity 0x102aed3ac main + 28
46 dyld_sim 0x102cf1fa0 start_sim + 20
47 dyld 0x102da5e50 start + 2544
I have the same issue. Sample code works on a simulator on iOS 15.5; but on iOS 16.2, it crashes immediately at NISession().
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 libdispatch.dylib 0x180137a70 _dispatch_assert_queue_fail + 116 1 libdispatch.dylib 0x180137a68 _dispatch_assert_queue_fail + 108 2 libdispatch.dylib 0x1801379fc dispatch_assert_queue + 188