Hi, I have a .NET MAUI app running on .NET 9. When I test locally in debug or release mode it works perfectly fine, but when testing from TestFlight it crashes almost immediately every time. I have sent the crash report to TestFlight and produced the symbolicated.crash file (attached), but I'm not sure it's helpful for understanding how to fix the issue.
If anyone can help me understand what the issue might be and any possible fixes it'd be very much appreciated.
I'm developing using Visual Studio 2022 paired to my Mac. I have distributed previously without issue, but now can't seem to, even after reverting recent code.
net9.0-ios
15.0
symbolicated.crash
Posts under iOS tag
200 Posts
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
A bottom accessory view is set on the UITabBarController. When changing the window size either by dragging the resizing grip or when going to portrait mode, the accessory view shrinks down to the smaller width. When resizing the window to make it larger, the accessory view doesn’t resize to the full available width.
During a workshop setup by Apple, folks from Apple told me that the view set as the content view of the UITabAccessory should not have its frame changed, either by using Auto Layout or by setting the frame. It seems logical since the view in the bottom accessory is supposed to resize accordingly to several factors, like when going inline inside the tab bar.
Am I missing something? Maybe there is additional setup required not mentioned in the dedicated video.
Feedback is FB19017330. It contains a sample project and videos demonstrating the issue. Reproduced on Xcode 26 beta 6 (17A5305f)
I copy and paste the sample code that setups the bottom accessory for good measure.
final class MiniPlayer: UIView {
let label = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
label.text = "Mini Player"
label.numberOfLines = 0
label.textAlignment = .center
addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
label.centerXAnchor.constraint(equalTo: centerXAnchor),
label.centerYAnchor.constraint(equalTo: centerYAnchor)
])
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
// MARK: - View Controller
class ViewController: UIViewController {
let rootTabBarController = UITabBarController()
let miniPlayer = MiniPlayer()
override func viewDidLoad() {
super.viewDidLoad()
let items: [UITab] = [
UITab(title: "Tab 1", image: UIImage(systemName: "archivebox.fill"), identifier: "tab-1") { _ in
UIViewController()
},
UITab(title: "Tab 2", image: UIImage(systemName: "books.vertical.fill"), identifier: "tab-2") { _ in
UIViewController()
},
UISearchTab { _ in
UIViewController()
}
]
rootTabBarController.tabs = items
rootTabBarController.view.backgroundColor = .secondarySystemBackground
view.addSubview(rootTabBarController.view)
rootTabBarController.view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
rootTabBarController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
rootTabBarController.view.topAnchor.constraint(equalTo: view.topAnchor),
rootTabBarController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
rootTabBarController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])
rootTabBarController.bottomAccessory = UITabAccessory(contentView: miniPlayer)
}
}
accessibilityUserInputLabels is working fine with any view I tried this on. Meaning that the control can be toggled with the provided alternative names when using Voice Control.
When setting this property on any UIBarButtonItem though, it seems Voice Control ignores the alternative names provided by setting accessibilityUserInputLabels. For comparison, accessibilityLabel works perfectly when set on UIBarButtonItem.
Is anyone facing the same issue?
Using Xcode 16.0 (16A242) on iOS 18
We are experiencing a large number of crashes in our production environment, mainly occurring on iOS 16 systems and iPhone 8 and iPhone X devices. The crash log and stack trace are as follows:
Error:
Assertion failed: (false) function _onqueue_rdar53306264_addWaiter file TubeManager.cpp line 1042
Crashed: com.apple.CFNetwork.LoaderQ
0 libsystem_kernel.dylib 0x7198 __pthread_kill + 8
1 libsystem_pthread.dylib 0xd5f8 pthread_kill + 208
2 libsystem_c.dylib 0x1c4b8 abort + 124
3 libsystem_c.dylib 0x70d8c err + 266
4 CFNetwork 0x1eb80 CFURLRequestSetMainDocumentURL + 6288
5 CFNetwork 0x44fd8 CFURLCacheRemoveAllCachedResponses + 22624
6 CFNetwork 0x39460 _CFHostIsDomainTopLevel + 968
7 CFNetwork 0x1f754 CFURLRequestSetMainDocumentURL + 9316
8 CFNetwork 0x233e0 CFURLRequestSetRequestPriority + 8792
9 CFNetwork 0x20d38 CFURLRequestCopyHTTPRequestBodyStream + 1612
10 CFNetwork 0x4f950 CFHTTPCookieStorageCopyCookies + 16276
11 CFNetwork 0x15878 CFURLRequestSetURL + 7600
12 libdispatch.dylib 0x637a8 _dispatch_call_block_and_release + 24
13 libdispatch.dylib 0x64780 _dispatch_client_callout + 16
14 libdispatch.dylib 0x3f6fc _dispatch_lane_serial_drain$VARIANT$armv81 + 600
15 libdispatch.dylib 0x401e4 _dispatch_lane_invoke$VARIANT$armv81 + 432
16 libdispatch.dylib 0x41304 _dispatch_workloop_invoke$VARIANT$armv81 + 1620
17 libdispatch.dylib 0x49f14 _dispatch_workloop_worker_thread + 608
18 libsystem_pthread.dylib 0x1bd0 _pthread_wqthread + 284
19 libsystem_pthread.dylib 0x1720 start_wqthread + 8
Have you encountered a similar issue before?
Trying to add some release test notes to a TestFlight build - but after clicking the blue save button nothing happens, nothing is saved.
I tried with two different browsers and two different Apple accounts, same thing with both.
Anybody else experiencing this issue?
On iOS 26 Beta, WKWebView consistently crashes when interacting with pages that use -webkit-user-select: none.
This issue does not reproduce in Safari, but only when the same content is loaded inside a WKWebView.
Steps to Reproduce:
Install iOS 26 Beta.
Open a WKWebView that loads a webpage with the following style applied globally:
-webkit-user-select: none;
Perform the following gesture sequence inside the WKWebView:
Double tap anywhere in the web content.
On the second tap, keep your finger pressed (do not lift).
While still holding the second tap, drag your finger across the screen (pan).
This sequence reliably produces the crash.
Expected Result:
No crash. The gesture should either be ignored or handled gracefully.
Actual Result:
The app crashes 100% of the time with the following exception:
#0 0x000000013f1a0874 in __pthread_kill ()
#1 0x00000001357522ec in pthread_kill ()
#2 0x00000001801ad950 in abort ()
#3 0x00000001802fa26c in __abort_message ()
#4 0x00000001802ea1a4 in demangling_terminate_handler ()
#5 0x0000000180077218 in _objc_terminate ()
#6 0x00000001802f9758 in std::__terminate ()
#7 0x00000001802fc7c0 in __cxxabiv1::failed_throw ()
#8 0x00000001802fc7a0 in __cxa_throw ()
#9 0x000000018009c1bc in objc_exception_throw ()
#10 0x00000001804f38f8 in +[NSException raise:format:] ()
#11 0x000000018c5fb570 in -[CALayer setPosition:] ()
#12 0x0000000185d02414 in -[UIView _backing_setPosition:] ()
#13 0x00000001867ec978 in -[UIView setCenter:] ()
#14 0x0000000186666468 in -[_UIEditMenuContentPresentation _displayPreparedMenu:titleView:reason:didDismissMenu:configuration:] ()
#15 0x0000000186666088 in __54-[_UIEditMenuContentPresentation _displayMenu:reason:]_block_invoke ()
#16 0x00000001867b3ed4 in -[UIEditMenuInteraction _editMenuPresentation:preparedMenuForDisplay:completion:] ()
#17 0x0000000186665fb0 in -[_UIEditMenuContentPresentation _displayMenu:reason:] ()
#18 0x0000000186665de4 in -[_UIEditMenuContentPresentation displayMenu:configuration:] ()
#19 0x00000001867b3260 in __58-[UIEditMenuInteraction presentEditMenuWithConfiguration:]_block_invoke ()
#20 0x00000001867b4c98 in __80-[UIEditMenuInteraction _prepareMenuAtLocation:configuration:completionHandler:]_block_invoke ()
#21 0x000000018653ff80 in __109-[UITextContextMenuInteraction _editMenuInteraction:menuForConfiguration:suggestedActions:completionHandler:]_block_invoke ()
#22 0x0000000186540448 in __107-[UITextContextMenuInteraction _querySelectionCommandsForConfiguration:suggestedActions:completionHandler:]_block_invoke ()
#23 0x000000018dba84f8 in WTF::Detail::CallableWrapper<WTF::CompletionHandler<void (IPC::Connection*, IPC::Decoder*)> IPC::Connection::makeAsyncReplyCompletionHandler<Messages::WebPage::RequestDocumentEditingContext, WTF::CompletionHandler<void (WebKit::DocumentEditingContext&&)>>(WTF::CompletionHandler<void (WebKit::DocumentEditingContext&&)>&&, WTF::ThreadLikeAssertion)::'lambda'(IPC::Connection*, IPC::Decoder*), void, IPC::Connection*, IPC::Decoder*>::call ()
#24 0x000000018dca14cc in WTF::Detail::CallableWrapper<WebKit::AuxiliaryProcessProxy::sendMessage(WTF::UniqueRef<IPC::Encoder>&&, WTF::OptionSet<IPC::SendOption>, std::__1::optional<IPC::ConnectionAsyncReplyHandler>, WebKit::AuxiliaryProcessProxy::ShouldStartProcessThrottlerActivity)::$_1, void, IPC::Connection*, IPC::Decoder*>::call ()
#25 0x000000018e2d5c54 in IPC::Connection::dispatchMessage ()
#26 0x000000018e2d6118 in IPC::Connection::dispatchIncomingMessages ()
#27 0x00000001997f9c58 in WTF::RunLoop::performWork ()
#28 0x00000001997fa930 in WTF::RunLoop::performWork ()
#29 0x000000018044d4dc in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#30 0x000000018044d424 in __CFRunLoopDoSource0 ()
#31 0x000000018044cc0c in __CFRunLoopDoSources0 ()
#32 0x000000018044bd84 in __CFRunLoopRun ()
#33 0x0000000180446e24 in _CFRunLoopRunSpecificWithOptions ()
#34 0x00000001924c19bc in GSEventRunModal ()
#35 0x00000001862217a8 in -[UIApplication _run] ()
#36 0x00000001862259d0 in UIApplicationMain ()
Same issues below.
https://developer.apple.com/forums/thread/796799
https://developer.apple.com/forums/thread/796501
https://developer.apple.com/forums/thread/796874
https://developer.apple.com/forums/thread/796686
Navigation Title no longer showing for first Tab in iOS/iPadOS 26 (Directives) in my app Starship SE Corps when running is Xcode 26 simulator and on iPad device itself running iPadOS 26 beta.
Launch app
Notice Navigation Title “Directives” is missing from top tab in Sidebar and Floating Tab View (iPad) and TabView (iOS).
Navigate to other tabs and Navigation Titles appear as expected.
Worked fine (as expected) in iOS/iPadOS 18.5, but broken in iOS/iPadOS 26.
Reference Feedback: FB17987650
I updated my watch to take advantage of the reactivated blood oxygen/O2 function, but with my iPhone on public beta 3, it still shows unavailable. Will there be an update to beta three to allow this newly reactivated Apple Watch feature to function?
A UISegmentedControl as a UIBarButtonItem (customView) is ignoring selectedSegmentTintColor on iOS 26, works fine on prior versions
I've submitted FB19660941 with a minimal Xcode workspace to reproduce the issue.
Has anyone else seen this and identified a workaround?
We have iOS application to connect and monitor the Wiser smart devices. This application supports WiFi access point change as well. When there is change in the WiFi, wiser devices supports for 3mins BLE mode for re-pairing. When BLE devices are newly commissioning, all devices are being able to discover by CoreBluetooth. But when we try to change the WiFi, Previously connected BLE devices are not being discoverable though they are in pairing mode.
My company has a server that supports ticket-based TLS session resumption (per RFC 5077).
We have done Wireshark captures that show that our iOS client app, which uses URLSession for REST and WebSocket connections to the server, is not sending the TLS "session_ticket" extension in the Client Hello package that necessary to enable ticket-based resumption with the server.
Is it expected that URLSession does not support ticket-based TLS session resumption?
If "yes", is there any way to tell URLSession to enable ticket-based session resumption? the lower-level API set_protocol_options_set_tls_tickets_enabled() hints that the overall TLS / HTTP stack on IOS does support ticket-based resumption, but I can't see how to use that low-level API with URLSession.
I can provide (lots) more technical details if necessary, but hopefully this is enough context to determine whether ticket-based TLS resumption is supported with URLSession.
Any tips / clarifications would be greatly appreciated.
My app does really large uploads. Like several GB. We use the AWS SDK to upload to S3.
It seemed like using BGContinuedProcessingTask to complete a set of uploads for a particular item may improve UX as well as performance and reliability.
When I tried to get BGContinuedProcessingTask working with the AWS SDK I found that the task would fail after maybe 30 seconds. It looked like this was because the app stopped receiving updates from the AWS upload and the task wants consistent updates. The AWS SDK always uses a background URLSession and this is not configurable. I understand the background URLSession runs in a separate process from the app and maybe that is why progress updates did not continue when the app was in the background.
Is it expected that BGContinuedProcessingTask and background URLSession are not really compatible? It would not be shocking since they are 2 separate background APIs.
Would the Apple recommendation be to use a normal URLSession for this, in which case AWS would need to change their SDK?
Or does Apple think that BGContinuedProcessingTask should just not be used with uploads? In other words use an upload specific API.
Thanks!
Topic:
App & System Services
SubTopic:
Processes & Concurrency
Tags:
iOS
Beta
Background Tasks
CFNetwork
Is iOS 26 Beta 6 available in the iOS Simulator?
I saw that the latest betas launched earlier this week. I updated my dev machine to macOS 26 Beta 6, however this release had no corresponding Xcode 26 Beta 6.
So I am still running Xcode Beta 5 and when I go into Settings -> Components within Xcode there is no option to install iOS 26 Beta 6. It's still running Beta 5 for macOS and iOS. Is that correct? My current assumption is that iOS Beta 6 is for physical devices only?
While testing my application on iOS beta 26, I am experiencing issues with the native UISegmentedControl component from UIKit. After implementing the control, I noticed that I am unable to switch to the second segment option—the selection remains fixed on the first segment regardless of user interaction. I have already reviewed the initial configuration of the control, the addition of the segments, and the implementation of the target-action, but the issue persists. I would like to understand what could be causing this behavior and if there are any specific adjustments or workarounds for iOS 26.
I created a minimal application containing only a UISegmentedControl to clearly demonstrate the issue.
I have no Apple developer subscription, out of curiosity i logged into Apple Developer and now, I have Beta updates assigned with my iPhone.
Can I unenroll from Apple developer program or remove/ disable/ erease/ delete Apple developer account?
An WWDC 25 a neutral value was demonstrated that allows the Slider to be 'coloured in' from the point of the neutral value to the current thumb position. Trying to use this in Dev release 1 I get errors saying no such modifier.
Was this functionality released in Dev Release 1 or am I using it incorrectly?
Hi,
I'm rewriting my game from SceneKit to RealityKit, and I'm having trouble implementing the following scenario:
I tap on the iPhone screen to select an Entity that I want to drag.
If an Entity was tapped, it should then be possible to drag it left, right, etc.
SceneKit solution:
func CGPointToSCNVector3(_ view: SCNView, depth: Float, point: CGPoint) -> SCNVector3 {
let projectedOrigin = view.projectPoint(SCNVector3Make(0, 0, Float(depth)))
let locationWithz = SCNVector3Make(Float(point.x), Float(point.y), Float(projectedOrigin.z))
return view.unprojectPoint(locationWithz)
}
and then I was calling:
SCNView().hitTest(location, options: [SCNHitTestOption.firstFoundOnly:true])
the code was called inside of the UIPanGestureRecognizer in my UIViewController.
Could I reuse that code or should I go with the SwiftUI approach - something like that:
var body: some View {
RealityView {
....
} .gesture(TapGesture().onEnded {
})
?
I already have this code:
@State private var location: CGPoint?
.onTapGesture { location in
self.location = location
}
I'm trying to identify the entity that was tapped within the RealityView like that:
RealityView { content in
let box: ModelEntity = createBox() // for now there is only one box, however there will be many boxes
content.add(box)
let anchor = AnchorEntity(world: [0, 0, 0])
content.add(anchor)
_ = content.subscribe(to: SceneEvents.Update.self) { event in
//TODO: find tapped entity, so that it could be dragged inside of the DragGesture()
}
Any help would be appreciated.
I also noticed that if I create a TapGesture like that:
TapGesture(count: 1)
.targetedToAnyEntity()
and add it to my view using .gesture() then it is not triggered.
Context:
I am currently developing an app using the Push-to-Talk (PTT) framework. I have reviewed both the PTT framework documentation and the CallKit demo project to better understand how to properly manage audio session activation and AVAudioEngine setup.
I am not activating the audio session manually. The audio session configuration is handled in the incomingPushResult or didBeginTransmitting callbacks from the PTChannelManagerDelegate.
I am using a single AVAudioEngine instance for both input and playback. The engine is started in the didActivate callback from the PTChannelManagerDelegate. When I receive a push in full duplex mode, I set the active participant to the user who is speaking.
Issue
When I attempt to talk while the other participant is already speaking, my input tap on the input node takes a few seconds to return valid PCM audio data. Initially, it returns an empty PCM audio block.
Details:
The audio session is already active and configured with .playAndRecord.
The input tap is already installed when the engine is started.
When I talk from a neutral state (no one is speaking), the system plays the standard "microphone activation" tone, which covers this initial delay. However, this does not happen when I am already receiving audio.
Assumptions / Current Setup
Because the audio session is active in play and record, I assumed that microphone input would be available immediately, even while receiving audio.
However, there seems to be a delay before valid input is delivered to the tap, only occurring when switching from a receive state to simultaneously talking.
Questions
Is this expected behavior when using the PTT framework in full duplex mode with a shared AVAudioEngine?
Should I be restarting or reconfiguring the engine or audio session when beginning to talk while receiving audio?
Is there a recommended pattern for managing microphone readiness in this scenario to avoid the initial empty PCM buffer?
Would using separate engines for input and output improve responsiveness?
I would like to confirm the correct approach to handling simultaneous talk and receive in full duplex mode using PTT framework and AVAudioEngine. Specifically, I need guidance on ensuring the microphone is ready to capture audio immediately without the delay seen in my current implementation.
Relevant Code Snippets
Engine Setup
func setup() {
let input = audioEngine.inputNode
do {
try input.setVoiceProcessingEnabled(true)
} catch {
print("Could not enable voice processing \(error)")
return
}
input.isVoiceProcessingAGCEnabled = false
let output = audioEngine.outputNode
let mainMixer = audioEngine.mainMixerNode
audioEngine.connect(pttPlayerNode, to: mainMixer, format: outputFormat)
audioEngine.connect(beepNode, to: mainMixer, format: outputFormat)
audioEngine.connect(mainMixer, to: output, format: outputFormat)
// Initialize converters
converter = AVAudioConverter(from: inputFormat, to: outputFormat)!
f32ToInt16Converter = AVAudioConverter(from: outputFormat, to: inputFormat)!
audioEngine.prepare()
}
Input Tap Installation
func installTap() {
guard AudioHandler.shared.checkMicrophonePermission() else {
print("Microphone not granted for recording")
return
}
guard !isInputTapped else {
print("[AudioEngine] Input is already tapped!")
return
}
let input = audioEngine.inputNode
let microphoneFormat = input.inputFormat(forBus: 0)
let microphoneDownsampler = AVAudioConverter(from: microphoneFormat, to: outputFormat)!
let desiredFormat = outputFormat
let inputFramesNeeded = AVAudioFrameCount((Double(OpusCodec.DECODED_PACKET_NUM_SAMPLES) * microphoneFormat.sampleRate) / desiredFormat.sampleRate)
input.installTap(onBus: 0, bufferSize: inputFramesNeeded, format: input.inputFormat(forBus: 0)) { [weak self] buffer, when in
guard let self = self else { return }
// Output buffer: 1920 frames at 16kHz
guard let outputBuffer = AVAudioPCMBuffer(pcmFormat: desiredFormat, frameCapacity: AVAudioFrameCount(OpusCodec.DECODED_PACKET_NUM_SAMPLES)) else { return }
outputBuffer.frameLength = outputBuffer.frameCapacity
let inputBlock: AVAudioConverterInputBlock = { inNumPackets, outStatus in
outStatus.pointee = .haveData
return buffer
}
var error: NSError?
let converterResult = microphoneDownsampler.convert(to: outputBuffer, error: &error, withInputFrom: inputBlock)
if converterResult != .haveData {
DebugLogger.shared.print("Downsample error \(converterResult)")
} else {
self.handleDownsampledBuffer(outputBuffer)
}
}
isInputTapped = true
}
Hi team, in iOS latest version 26.0, we are getting searchBar at bottom of the screen. Is there any option to change the position of the search? I need to move it to top as like in previous iOS version.
When a UIPageViewController is pushed in a UINavigationController, the leading swipe action from middle of screen dismisses the PageViewController instead of going to previous page.
When the Example code is opened from Xcode 16.4.0,
✅ Left Swipe action from left screen edge of screen dismisses the Page View Controller.
✅ Left Swipe action from middle of screen goes to previous Page in Page View Controller
When the Example code is opened from Xcode 26.0 - Beta 6,
✅ Left Swipe action from left screen edge of screen dismisses the Page View Controller.
❌ Left Swipe action from middle of screen sometimes goes to previous page and sometimes dismisses the Page View Controller.
Example code that the issue occurs:
import Foundation
import UIKit
import PlaygroundSupport
PlaygroundPage.current.setLiveView(
UINavigationController(rootViewController: RootViewController())
)
class RootViewController: UIViewController {
lazy var pageVCButton: UIButton = {
let button = UIButton()
button.setTitle("Open Page VC", for: .normal)
button.setTitleColor(.label, for: .normal)
button.addAction(UIAction(handler: { [weak self] _ in
self?.didTapPageVCButton()
}), for: .touchUpInside)
return button
}()
lazy var pageContainerViewController = PageContainerViewController(startIndex: 3)
func didTapPageVCButton() {
print("didTapPageVCButton")
navigationController?.pushViewController(pageContainerViewController, animated: true)
}
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemBackground
addOpenPageVCButton()
}
private func addOpenPageVCButton() {
view.addSubview(pageVCButton)
pageVCButton.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
pageVCButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),
pageVCButton.centerYAnchor.constraint(equalTo: view.centerYAnchor),
])
}
}
class PageContainerViewController: UIViewController {
lazy var pageViewController: UIPageViewController = {
let pageViewController = UIPageViewController(
transitionStyle: .scroll,
navigationOrientation: .horizontal,
options: nil
)
pageViewController.dataSource = self
pageViewController.delegate = self
return pageViewController
}()
lazy var pages: [ColouredViewController] = [
ColouredViewController(backgroundColor: .red),
ColouredViewController(backgroundColor: .blue),
ColouredViewController(backgroundColor: .green),
ColouredViewController(backgroundColor: .yellow),
ColouredViewController(backgroundColor: .brown),
ColouredViewController(backgroundColor: .link),
ColouredViewController(backgroundColor: .cyan),
]
var startIndex = 0
init(startIndex: Int) {
super.init(nibName: nil, bundle: nil)
self.startIndex = startIndex
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.title = "Page View Controller"
print(pageViewController.gestureRecognizers)
setupPageViewController()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
private func setupPageViewController() {
addChild(pageViewController)
view.addSubview(pageViewController.view)
pageViewController.didMove(toParent: self)
pageViewController.view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
pageViewController.view.topAnchor.constraint(equalTo: view.topAnchor),
pageViewController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor),
pageViewController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
pageViewController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
])
pageViewController.setViewControllers([pages[startIndex]], direction: .forward, animated: true)
}
}
extension PageContainerViewController: UIPageViewControllerDataSource {
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
print("Leading Swipe")
guard let viewController = viewController as? ColouredViewController else { return nil }
guard let currentPageIndex = pages.firstIndex(of: viewController) else { return nil }
if currentPageIndex == 0 { return nil }
return pages[currentPageIndex - 1]
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
print("Trailing Swipe")
guard let viewController = viewController as? ColouredViewController else { return nil }
guard let currentPageIndex = pages.firstIndex(of: viewController) else { return nil }
if currentPageIndex == pages.count - 1 { return nil }
return pages[currentPageIndex + 1]
}
}
extension PageContainerViewController: UIPageViewControllerDelegate {}
class ColouredViewController: UIViewController {
var backgroundColor: UIColor?
init(backgroundColor: UIColor) {
super.init(nibName: nil, bundle: nil)
self.backgroundColor = backgroundColor
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = backgroundColor
}
}