I have this Objective-C code that works well if placed inside viewDidAppear method - rotates view into the Portrait orientation;
UIWindowScene *windowScene = self.view.window.windowScene;
if (!windowScene) { return; }
UIWindowSceneGeometryPreferences *preferences = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:UIInterfaceOrientationMaskPortrait];
[windowScene requestGeometryUpdateWithPreferences:preferences errorHandler:^(NSError * _Nonnull error) {
// Handle error here
}];
Now I need to do that same rotation after user pressed Read button but before the selected document is loaded in another view. The problem - I can't figure out how to force view update after the code is executed. I see initial view rotated only after exiting that selected document, but I need it rotated before entering it.
Thank you
UIKit
RSS for tagConstruct and manage graphical, event-driven user interfaces for iOS or tvOS apps using UIKit.
Post
Replies
Boosts
Views
Activity
I want to use CUPS in iOS for printing and it is mentioned at many places that we can use cups for printing in ios .But when i import library cups/cups.h ,xcode is giving error "cups/cups.h not found".
code i am using in a objective c file :
import <cups/cups.h>
cups_dest_t *dest;
int num_options;
cups_option_t *options;
int job_id;
/* Print a single file */
job_id = cupsPrintFile(dest->name, "/usr/share/cups/data/testprint.ps",
"Test Print", num_options, options);
Do i need to intall some driver or any library to make it work ? or is it the case that CUPS is not available for iOS?
I am getting an error that crashes my app and takes me to AppDelegate file showing an error message
Thread 1: "Application tried to present modally a view controller <MyApp.CanvasViewController: 0x7fca1c70f610> that is already being presented by <UINavigationController: 0x7fca1d837800>
Basically what I was trying to do was to save an instance of UIViewController into app delegate protocol and then show every saved instance into a UITableView cell in which each cell will have a button to go back to that instance of the UIViewController.
@objc func actbuttonFuncCall(_ sender: UIButton) {
let index = sender.tag
// access the content of the singleton class where the struct.view: UIVIewController is saved
let identifier = VCs.shared.storedVc[index]?.view
let vc = identifier
print("tool bar button clicked! \(vc)")
vc?.modalPresentationStyle = .fullScreen
vc?.modalTransitionStyle = .coverVertical
// set main CanvasViewController as default value
present(vc ?? CanvasViewController(), animated: true)
}
That is to allow users to go back and forward into the main UIViewController where all the project functionality is executed. Is there anything I should consider doing to achieve my goal?
When a user updates their device to iOS 17 (any version) on a device with MDM, our app crashes but only on some device, not all. The same app runs fine on iOS 16. We cannot recreate the issue in-house and even our customers cannot reliably recreate the crash as it only happens on some devices and not others.
The crash we get is:
SIGABRT: UICollectionView internal inconsistency: missing final attributes for cell
Once the device gets this crash, the only way to fix it is to delete and reinstall the app and then everything works fine.
Anyone having a similar issue with iOS 17 and MDM?
I have collection view with hierarchical data source. Because of that, I create some cells with UICellAccessoryOutlineDisclosure accessory with style UICellAccessoryOutlineDisclosureStyleCell, so one can either tap on cell to open detail view or tap on outline disclosure accessory to reveal hidden child data.
Question:
How should I configure outline disclosure accessory to work with VoiceOver on?
It works fine without VoiceOver, but with VoiceOver it seems, that any gesture always leads to opening detail view.
I have four models: Vegetables, Fruits, Herbs and Condiments. Each model has separate collection view, and different cell identifier. Data is successfully fetched which I confirmed by printing number of objects.
I have used DiffableDataSource, where data source is initialized as follows:
Source & snapshot:
var dataSource: UICollectionViewDiffableDataSource<String, NSManagedObjectID>?
typealias DataSource = UICollectionViewDiffableDataSource<String, NSManagedObjectID>
typealias Snapshot = NSDiffableDataSourceSnapshot<String, NSManagedObjectID>
Setting up data source:
private func setupDataSource<T:NSManagedObject>(for collectionView:UICollectionView,
with identifier: String,
of entity: T.Type)
->DataSource
{
let dataSource = DataSource(
collectionView: collectionView,
cellProvider: {(collectionView, indexPath, managedObjectID) -> UICollectionViewCell? in
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) as! KitchenCollectionViewCell
if let pantry = try? self.kitchenCoreDataStack.managedContext.existingObject(with: managedObjectID) as? T {
self.configure(cell: cell, for: pantry)
}
return cell
})
return dataSource
}
When breakpoint is set in above code, it doesn't go past this line:
cellProvider: {(collectionView, indexPath, manageObjectID)
Snapshot code to reflect changes:
extension KitchenViewController: NSFetchedResultsControllerDelegate{
func applySnapshot(animatingDifferences: Bool){
let snapshot = Snapshot()
dataSource?.apply(snapshot, animatingDifferences: animatingDifferences)
}
}
I called datasource function with :
dataSource = setupDataSource(for: firstCollectionView, with: "fruits", of: Fruits.self)
Hello everyone,
Is there a better solution than my approach out there to convert an image to data and back?
@Model
class User {
var name: String
@Attribute(.externalStorage) var image: Data?
var createdAt: Date
init(name: String, image: Data, createdAt: Date = .now) {
self.name = name
self.image = image
self.createdAt = createdAt
}
}
if let selectedPhotoData = imageData,
let uiImage = UIImage(data: selectedPhotoData) {
Image(uiImage: uiImage)
.resizable()
.scaledToFill()
.frame(width: 300, height: 300, alignment: .center)
.clipShape(Circle())
}
.task(id: selectedPhoto) {
if let data = try? await selectedPhoto?.loadTransferable(type: Data.self) {
imageData = data
}
}
I'm working on converting an app to SwiftUI, and I have a menu that used to be several table cells in a storyboard, but I moved it to an embedded SwiftUI view instead.
Here's the old way (from override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell ):
cellReuseID = "BillingToolsCell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellReuseID, for: indexPath)
if let billingToolsCell = cell as? BillingToolsCell {
billingToolsCell.billingToolsOptions.text = billingTools[indexPath.row].title
// Accessibility
billingToolsCell.isAccessibilityElement = true
billingToolsCell.accessibilityIdentifier = "Billing_\(billingTools[indexPath.row].title.replacingOccurrences(of: " ", with: ""))"
}
return cell
And here's the new way I'm creating the cell:
cellReuseID = "BillingToolsSwiftUI"
if let cell = tableView.dequeueReusableCell(withIdentifier: cellReuseID, for: indexPath) as? SwiftUIHostTableViewCell<BillingToolsView> {
let view = BillingToolsView(billingToolVM: BillingToolViewModel()) { segueID in
self.performSegue(segueID: segueID)
}
cell.host(view, parent: self)
return cell
}
Here's the swiftUI view:
struct BillingToolsView: View {
@StateObject var billingToolVM: BillingToolViewModel
var navigationCallback: (String) -> Void
var body: some View {
VStack {
VStack{
ForEach(self.billingToolVM.billingToolList, id: \.self) { tool in
Button {
navigationCallback(tool.segueID)
} label: {
BillingToolsRowView(toolName: tool.title)
Divider().foregroundColor(AFINeutral800_SwiftUI)
}
.accessibilityIdentifier("Billing_\(tool.title.replacingOccurrences(of: " ", with: ""))")
}
}
.padding(.vertical)
.padding(.leading)
.background(AFINeutral0_SwiftUI)
}
}
}
If I check the accessibility inspector, I can see the identifier - here it is showing Billing_PaymentHistory:
But when the testers try to run their tests in Appium, they don't see any identifier at all:
Did I mess up setting up the accessibility identifier somehow? Or do the testers need to update their script?
Hello,
For the past month, I've been learning to use UIKit on Xcode to prepare for the Swift Student Challenge. However, I can't find a way to use my newly acquired skills in App Playgrounds. Do they strictly require SwiftUI? Is there a way to use UIKit and Storyboards?
Refer to ConferenceNewsFeedViewController in the attached project
Enable drag drop for collectionview
Increase the text/content in a few cells: refer ConferenceNewsController
Result: The cells behave weird: move up and down and shake , when trying to drag drop. This happens if the cell heights are not identical and if estimated values are used in compositional layout.
Anyone facing similar issues?
All the documentation I've found so far is made for SwiftUI (I understand it was primarily designed for use with SwiftUI), but I'm still not able to find if there is even a way to do it. I tried to implement this very simple tutorial (https://www.youtube.com/watch?v=oloHJn1kj3w) and since it is done with SwiftUI, I tried to make a hybrid using UIHostingController, but had no luck. I made sure the configuration was set correctly, and I think it is because when I enter the app's settings (from the iPhone's settings app) the live activities button is there and turned on.
Knowing how to do it would be awesome, but I would be satisfied with at least knowing if it is even possible, before wasting more time. Thanks.
I have tried below code to open [Settings(App) -&gt; Bluetooth Settings] but it is navigating to App permission screen instead of Bluetooth Settings. I have tried to search but didn't get any latest documentation regarding it. Is there any way to do this?
guard let url = URL(string: UIApplication.openSettingsURLString) else {
return
}
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
This is an often asked question, but I just have a partial answer so far.
There are some views (not all) that I need to present in Portrait only when running on iPhone.
If I come from a TabBar, I just add the following code in the TabBar controller
override open var supportedInterfaceOrientations : UIInterfaceOrientationMask {
if UIDevice.current.userInterfaceIdiom == .phone {
return [.portrait, .portraitUpsideDown]
}
}
But I need to do the same when I get to the destination VC by a segue fired from a plain UIViewController or a Cell in a TableView.
If I put the code in the destination controller, it has no effect.
If I put in the originating VC, it works when segue is triggered from code (case 2 below).
But I cannot make it work when segue is triggered in storyboard from the accessory action in the cell of the TableView.
Where should I declare the supportedInterfaceOrientations ?
Should I do it in the navigation root ? If so, how ?
I tried in an extension UINavigationController, to no avail.
or should I trigger the segue from accessory, not directly in storyboard but through an IBAction in code ?
If that may help, an overview of storyboard setup:
Also tried solution described here to no avail either: https://www.appsdeveloperblog.com/disable-rotation-of-uiviewcontroller-embedded-into-uinavigationcontroller/
protocol UIViewConstraint {
associatedtype Anchor: AnyObject
var anchor: NSLayoutAnchor<Anchor>? { get }
var attribute: NSLayoutConstraint.Attribute { get }
var value: UIView.ConstraintValue { get }
}
extension UIView {
struct Constraint<Anchor: AnyObject>: UIViewConstraint {
var anchor: NSLayoutAnchor<Anchor>?
var attribute: NSLayoutConstraint.Attribute
var value: UIView.ConstraintValue
}
}
extension UIViewConstraint where Anchor == NSLayoutYAxisAnchor {
static func top(_ value: UIView.ConstraintValue, to anchor: NSLayoutYAxisAnchor? = nil) -> UIView.Constraint<NSLayoutYAxisAnchor> {
UIView.Constraint(anchor: anchor, attribute: .top, value: value)
}
static func bottom(_ value: UIView.ConstraintValue, to anchor: NSLayoutYAxisAnchor? = nil) -> UIView.Constraint<NSLayoutYAxisAnchor> {
UIView.Constraint(anchor: anchor, attribute: .bottom, value: value)
}
}
extension UIView {
struct ConstraintValue {
var constant: CGFloat
}
}
extension UIView.ConstraintValue: ExpressibleByIntegerLiteral {
init(integerLiteral value: Int) {
self.init(constant: CGFloat(value))
}
}
extension UIView {
func active<each Anchor>(_ constraint: repeat UIView.Constraint<each Anchor>) {
(repeat _active(each constraint))
}
func active2<each Constraint: UIViewConstraint>(_ constraint: repeat each Constraint) {
(repeat _active(each constraint))
}
func active3(_ constraint: any UIViewConstraint...) {
}
private func _active<T: UIViewConstraint>(_ anchor: T) {
//
}
}
let superView = UIView()
let view = UIView()
superView.addSubview(view)
view.active(
.top(10), // Cannot convert value of type 'Int' to expected argument type 'UIView.ConstraintValue'
.bottom(20) // Cannot convert value of type 'Int' to expected argument type 'UIView.ConstraintValue'
)
view.active2(
.top(10), // Cannot convert value of type 'Int' to expected argument type 'UIView.ConstraintValue'
.bottom(20) // Cannot convert value of type 'Int' to expected argument type 'UIView.ConstraintValue'
)
let top: UIView.Constraint<NSLayoutYAxisAnchor> = .top(10) // ✅
let bottom: UIView.Constraint<NSLayoutYAxisAnchor> = .bottom(20) // ✅
view.active(top, bottom) // ✅
view.active2(top, bottom) // ✅
I'm looking to gather the Core Web Vitals for the performance of the sites I open in my app using WKWebView. Specifically I'm looking for events that indicate the following:
FCP: First Contentful Paint
LCP: Largest Contentful Paint
The idea is taken from the following article: https://web.dev/articles/vitals
Does WKWebView generate those events? If so, could you please provide a reference? I was unable to find anything in my research.
If it does not generate those events, could you provide some guidance on how they could be generated by maybe injecting a script or deriving those events from some existing events?
I understand that this might be a complex query. So it would be great if you can provide partial answers while you look to help me with the rest of the answers and solutions.
Appreciate your help with this.
Vivandro.
Is anyone having 'oddness' with ios 17.4 b1 either not calling delegate - (UIInterfaceOrientationMask)supportedInterfaceOrientations or simply ignoring it.
For example apps that are locked in portrait (but do have to support rotation at different parts of the app) seem to be freely be able to rotate even on places it shoudnt. Im freely allowed to rotate the youtube app for example in landscape, at the main screen, not just on the video player. Im seeing this in other apps to that are locked portrait. But if you kill the app, and restart the app then it will not rotate. something funky was changed or a bug.
ive never seen this before in ios 17.0 - 17.3
Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.
`Triggered by Thread: 36
Last Exception Backtrace:
0 CoreFoundation 0x1a1585e88 __exceptionPreprocess + 164 (NSException.m:202)
1 libobjc.A.dylib 0x19a8bf8d8 objc_exception_throw + 60 (objc-exception.mm:356)
2 CoreAutoLayout 0x1bde18e84 _AssertAutoLayoutOnAllowedThreadsOnly + 328 (NSISEngine.m:0)
3 CoreAutoLayout 0x1bde0f9b4 -[NSISEngine _optimizeWithoutRebuilding] + 72 (NSISEngine.m:1709)
4 CoreAutoLayout 0x1bde0f8e4 -[NSISEngine optimize] + 96 (NSISEngine.m:1683)
5 CoreAutoLayout 0x1bde0f670 -[NSISEngine performPendingChangeNotifications] + 104 (NSISEngine.m:677)
6 UIKitCore 0x1a373fa44 -[UIView(Hierarchy) layoutSubviews] + 128 (UIView.m:13091)
7 UIKitCore 0x1a373e020 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1980 (UIView.m:18554)
8 QuartzCore 0x1a2c139ec CA::Layer::layout_if_needed(CA::Transaction*) + 500 (CALayer.mm:10226)
9 QuartzCore 0x1a2c270a0 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 148 (CALayer.mm:2516)
10 QuartzCore 0x1a2c385b0 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 456 (CAContextInternal.mm:2708)
11 QuartzCore 0x1a2c6d5ec CA::Transaction::commit() + 652 (CATransactionInternal.mm:431)
12 QuartzCore 0x1a2cbdab4 CA::Transaction::release_thread(void*) + 228 (CATransactionInternal.mm:634)
13 libsystem_pthread.dylib 0x1ee5dcbd8 _pthread_tsd_cleanup + 620 (pthread_tsd.c:300)
14 libsystem_pthread.dylib 0x1ee5df674 _pthread_exit + 84 (pthread.c:1719)
15 libsystem_pthread.dylib 0x1ee5dc0e0 _pthread_wqthread_exit + 76 (pthread.c:2578)
16 libsystem_pthread.dylib 0x1ee5dbe80 _pthread_wqthread + 424 (pthread.c:2612)
17 libsystem_pthread.dylib 0x1ee5dbb98 start_wqthread + 8 (:-1)
Thread 36 Crashed:
0 libsystem_c.dylib 0x00000001a8c11404 __abort + 160 (abort.c:167)
1 libsystem_c.dylib 0x00000001a8bb9c98 abort + 192 (abort.c:126)
2 libc++abi.dylib 0x00000001ee522b8c abort_message + 132 (abort_message.cpp:78)
3 libc++abi.dylib 0x00000001ee512a80 demangling_terminate_handler() + 336 (cxa_default_handlers.cpp:71)
4 libobjc.A.dylib 0x000000019a8c5d3c _objc_terminate() + 144 (objc-exception.mm:498)
5 SansiroLive 0x0000000104fa4f7c BLYCPPExceptionTerminate() + 2044
6 libc++abi.dylib 0x00000001ee521f28 std::__terminate(void ()()) + 20 (cxa_handlers.cpp:59)
7 libc++abi.dylib 0x00000001ee524c2c __cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception) + 36 (cxa_exception.cpp:152)
8 libc++abi.dylib 0x00000001ee524bd8 __cxa_throw + 140 (cxa_exception.cpp:283)
9 libobjc.A.dylib 0x000000019a8bfa38 objc_exception_throw + 412 (objc-exception.mm:385)
10 CoreAutoLayout 0x00000001bde18e84 _AssertAutoLayoutOnAllowedThreadsOnly + 328 (NSISEngine.m:0)
11 CoreAutoLayout 0x00000001bde0f9b4 -[NSISEngine _optimizeWithoutRebuilding] + 72 (NSISEngine.m:1709)
12 CoreAutoLayout 0x00000001bde0f8e4 -[NSISEngine optimize] + 96 (NSISEngine.m:1683)
13 CoreAutoLayout 0x00000001bde0f670 -[NSISEngine performPendingChangeNotifications] + 104 (NSISEngine.m:677)
14 UIKitCore 0x00000001a373fa44 -[UIView(Hierarchy) layoutSubviews] + 128 (UIView.m:13091)
15 UIKitCore 0x00000001a373e020 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1980 (UIView.m:18554)
16 QuartzCore 0x00000001a2c139ec CA::Layer::layout_if_needed(CA::Transaction*) + 500 (CALayer.mm:10226)
17 QuartzCore 0x00000001a2c270a0 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 148 (CALayer.mm:2516)
18 QuartzCore 0x00000001a2c385b0 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 456 (CAContextInternal.mm:2708)
19 QuartzCore 0x00000001a2c6d5ec CA::Transaction::commit() + 652 (CATransactionInternal.mm:431)
20 QuartzCore 0x00000001a2cbdab4 CA::Transaction::release_thread(void*) + 228 (CATransactionInternal.mm:634)
21 libsystem_pthread.dylib 0x00000001ee5dcbd8 _pthread_tsd_cleanup + 620 (pthread_tsd.c:300)
22 libsystem_pthread.dylib 0x00000001ee5df674 _pthread_exit + 84 (pthread.c:1719)
23 libsystem_pthread.dylib 0x00000001ee5dc0e0 _pthread_wqthread_exit + 76 (pthread.c:2578)
24 libsystem_pthread.dylib 0x00000001ee5dbe80 _pthread_wqthread + 424 (pthread.c:2612)
25 libsystem_pthread.dylib 0x00000001ee5dbb98 start_wqthread + 8 (:-1)
`
Apple in all their wisdom has deprecated almost every API that can be used to get the interface orientation because they want developers to treat an orientation change as a simple size change.
However, there are other uses for the interface orientation other than adjusting the UI. Since the camera is fixed to the device, and does not rotate with the interface, images from the camera need to be adjusted for orientation when displaying and/or processing them for computer vision tasks. Using traits is not a reliable way of determining the orientation, especially when running on an iPad.
What is the recommended way to determine the relative angle of the camera in relation to the interface now all the interfaceOrientation APIs are deprecated? And specifically: how to get a notification of an interface orientation change?
Hey there,
we are seeing following crash in our firebase cras console:
Fatal Exception: NSInvalidArgumentException
-[_UISnapshotWindow actualSceneBounds]: unrecognized selector sent to instance 0x10ff840e0
Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0xec69c __exceptionPreprocess
1 libobjc.A.dylib 0x2bc80 objc_exception_throw
2 CoreFoundation 0x17cfdc +[NSObject(NSObject) _copyDescription]
3 UIKitCore 0xe31bcc -[UIResponder doesNotRecognizeSelector:]
4 CoreFoundation 0x31e08 ___forwarding___
5 CoreFoundation 0x172950 _CF_forwarding_prep_0
6 UIKitCore 0x265bd8 -[UIUndoGestureInteraction didMoveToView:]
7 UIKitCore 0xb3510 _setInteractionView
8 UIKitCore 0xb345c -[UIView(Dragging) addInteraction:]
9 UIKitCore 0x13d1d4 -[UIEditingOverlayViewController _addInteractions]
10 UIKitCore 0x13c9b0 -[UIViewController _setViewAppearState:isAnimating:]
11 UIKitCore 0x18ff90 __52-[UIViewController _setViewAppearState:isAnimating:]_block_invoke_2
12 UIKitCore 0x18fe28 __52-[UIViewController _setViewAppearState:isAnimating:]_block_invoke
13 CoreFoundation 0x353f4 __NSARRAY_IS_CALLING_OUT_TO_A_BLOCK__
14 CoreFoundation 0x66670 -[__NSArrayI enumerateObjectsWithOptions:usingBlock:]
15 UIKitCore 0x13cb10 -[UIViewController _setViewAppearState:isAnimating:]
16 UIKitCore 0xad8f0 -[UIViewController __viewDidAppear:]
17 UIKitCore 0x1bc624 __64-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]_block_invoke
18 UIKitCore 0xadad0 -[UIViewController _executeAfterAppearanceBlock]
19 UIKitCore 0xab35c -[_UIAfterCACommitBlock run]
20 UIKitCore 0xab140 -[_UIAfterCACommitQueue flush]
21 UIKitCore 0xab058 _runAfterCACommitDeferredBlocks
22 UIKitCore 0xaade4 _cleanUpAfterCAFlushAndRunDeferredBlocks
23 UIKitCore 0xaace0 _UIApplicationFlushCATransaction
24 UIKitCore 0xaa7e4 _UIUpdateSequenceRun
25 UIKitCore 0xa9ed4 schedulerStepScheduledMainSection
26 UIKitCore 0xa9f90 runloopSourceCallback
27 CoreFoundation 0x3712c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
28 CoreFoundation 0x363a8 __CFRunLoopDoSource0
29 CoreFoundation 0x34b5c __CFRunLoopDoSources0
30 CoreFoundation 0x33898 __CFRunLoopRun
31 CoreFoundation 0x33478 CFRunLoopRunSpecific
32 GraphicsServices 0x34f8 GSEventRunModal
33 UIKitCore 0x22c62c -[UIApplication _run]
34 UIKitCore 0x22bc68 UIApplicationMain
35 appname*** 0x40bc main + 3 (main.swift:3)
36 ??? 0x1c48c2dcc (Fehlt)
What we can see is, that
public func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) { }
is being executed while the app has the state background. After entering a ViewController, the app seems to crash.
Does anybody had a similar crashlog and maybe a approach how we could solve it?
here is the code:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destVC = segue.destination as! ColorsDetailVC
destVC.cdvc_color = sender as? UIColor
}