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.
UIKit
RSS for tagConstruct and manage graphical, event-driven user interfaces for iOS or tvOS apps using UIKit.
Post
Replies
Boosts
Views
Activity
I have tried below code to open [Settings(App) -> 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
}
Hello, I am looking for some help today about a crash that randomly appeared for no explicit reason. A bit of context, I have 2 apps/targets within the project and the only thing that changes between the two is pretty much the API and the colors/logos.
I have published an update for both apps, the related code hasn't changed since the previous versions (it has been in production for 6 months already), and it's only crashing in the same app, not in the other one somehow. It happens on multiple iOS versions and devices as well. Of course, I am unable to reproduce the crash.
I am using Firebase Crashlytics, which gives me this error message :
Fatal Exception: NSInternalInconsistencyException - You must provide a value (key=contents)
And in the Xcode Organizer, the highlighted stack trace line responsible for the crash is the following :
3 UIKitCore 0x1c2ad5970 -[_UIViewDeferredAnimation addAnimationFrameForValue:] + 216 (UIView.m:2792)
About the code, I have a custom searchBar and a cancelButton embedded in a UIStackView, I am animating the cancelButton visibility using .isHidden to replicate the experience you get when using a UISearchController in the navigationBar.
About the crash, it seems to be triggered when animating keyframes using UIView.animateKeyframes, with multiple UIView.addKeyframe within the animation block, at least that's why I understand from the stack trace.
The code is really simple, when the searchBarTextField becomes the first responder and begins editing, I animate the cancelButton in. The cancelButtonAnimationOptions are the followings : .curveEaseInOut, .beginFromCurrentState and .allowUserInteraction.
func textFieldDidBeginEditing(_ textField: UITextField) {
showSearchBarCancelButton()
}
func showSearchBarCancelButton() {
let duration = Layout.animationDuration
let options = Layout.cancelButtonAnimationOptions
UIView.animateKeyframes(withDuration: duration, delay: 0, options: options, animations: {
UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 1, animations: {
self.cancelButton.isHidden = false
self.cancelButton.superview?.layoutIfNeeded()
})
UIView.addKeyframe(withRelativeStartTime: 0.7, relativeDuration: 0.3, animations: {
self.cancelButton.alpha = 1
})
})
}
Here is a preview of the stack trace :
(Check Log.crash in the attachments for the full version) :
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x1c057de88 __exceptionPreprocess + 164 (NSException.m:202)
1 libobjc.A.dylib 0x1b98ab8d8 objc_exception_throw + 60 (objc-exception.mm:356)
2 Foundation 0x1bae99b4c -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 188 (NSException.m:242)
3 UIKitCore 0x1c2ad5970 -[_UIViewDeferredAnimation addAnimationFrameForValue:] + 216 (UIView.m:2792)
4 UIKitCore 0x1c2ad5208 -[_UIViewDeferredKeyframeAnimation addAnimationFrameForValue:] + 72 (UIView.m:2901)
5 UIKitCore 0x1c2ad5148 __93-[UIViewKeyframeAnimationState addKeyframeWithRelativeStartTime:relativeDuration:animations:]_block_invoke + 368 (UIView.m:2651)
6 CoreFoundation 0x1c0587588 __NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK__ + 24 (NSDictionaryHelpers.m:10)
7 CoreFoundation 0x1c0611bc0 -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 212 (NSDictionaryM_Common.h:311)
8 UIKitCore 0x1c2b636c8 -[UIViewKeyframeAnimationState addKeyframeWithRelativeStartTime:relativeDuration:animations:] + 156 (UIView.m:2638)
9 UIKitCore 0x1c2b635dc +[UIView(UIViewKeyframeAnimations) addKeyframeWithRelativeStartTime:relativeDuration:animations:] + 132 (UIView.m:15468)
10 MyApp 0x102b657f8 closure #1 in FavoritesViewController.showSearchBarCancelButton() + 196 (FavoritesViewController+Search.swift:45)
11 MyApp 0x102c04198 thunk for @escaping @callee_guaranteed () -> () + 28 (<compiler-generated>:0)
12 UIKitCore 0x1c28011e4 +[UIView _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 512 (UIView.m:15213)
13 UIKitCore 0x1c292e140 +[UIView(UIViewKeyframeAnimations) animateKeyframesWithDuration:delay:options:animations:completion:] + 156 (UIView.m:15458)
14 MyApp 0x102b655a4 FavoritesViewController.showSearchBarCancelButton() + 44 (FavoritesViewController+Search.swift:44)
15 MyApp 0x102b655a4 FavoritesViewController.textFieldDidBeginEditing(_:) + 44 (FavoritesViewController+Search.swift:12)
16 MyApp 0x102b655a4 @objc FavoritesViewController.textFieldDidBeginEditing(_:) + 224 (<compiler-generated>:11)
17 UIKitCore 0x1c2c949c8 -[UITextField _notifyDidBeginEditing] + 104 (UITextField.m:1910)
18 UIKitCore 0x1c2952554 -[UITextField _becomeFirstResponder] + 196 (UITextField.m:1842)
19 UIKitCore 0x1c294ffa4 -[UIResponder becomeFirstResponder] + 516 (UIResponder.m:392)
20 UIKitCore 0x1c294fd90 -[UIView(Hierarchy) becomeFirstResponder] + 120 (UIView.m:12379)
21 UIKitCore 0x1c2803bc4 -[UITextField becomeFirstResponder] + 152 (UITextField.m:1496)
22 MyApp 0x102ab6840 CustomSearchBar.onSearchBarTap(_:) + 36 (CustomSearchBar.swift:36)
23 MyApp 0x102ab6840 @objc CustomSearchBar.onSearchBarTap(_:) + 88 (<compiler-generated>:35)
Thanks for your help!
This app allows to take photos.
It works OK, but since recently I get the following error message:
ERROR: PHOTO not found in table CameraUI-SpatialVideo of bundle CFBundle 0x283e96220 </System/Library/PrivateFrameworks/CameraUI.framework> (not loaded)
What is this spatial video ? I'm just using still images, not using CameraUI.framework.
Since the release of iOS 17, my application is no longer recognized as the default option for opening my custom file extension via AirDrop. I understand that Apple has modified AirDrop functionality to integrate more closely with the Files app. However, within the Files app, my file package is erroneously identified as a folder, thus ignoring my specified file extension. Additionally, my attempts to utilize UIDocumentPickerViewController for opening these files have been unsuccessful, as it fails to recognize the file type.
I have explored various approaches with UIDocumentPickerViewController, including the following implementation:
let importCustomFiles = UIAlertAction(title: "Import custom file", style: .default) { _ in
let myExtensionType = UTType(filenameExtension: "MyExtension")!
let pickerViewController = UIDocumentPickerViewController(forOpeningContentTypes: [myExtensionType])
pickerViewController.delegate = self
pickerViewController.allowsMultipleSelection = false
pickerViewController.shouldShowFileExtensions = true
self.present(pickerViewController, animated: true, completion: nil)
}
Below is an excerpt from my Info.plist file, detailing the relevant configurations for my custom file extension:
<!-- MyExtension Document Type -->
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array>
<string>MyApp File Icon</string>
</array>
<key>CFBundleTypeName</key>
<string>Angles MyExtension</string>
<key>LSHandlerRank</key>
<string>Default</string>
<key>LSItemContentTypes</key>
<array>
<string>au.com.mycompany.myapp.MyExtension</string>
</array>
<key>LSTypeIsPackage</key>
<true/>
</dict>
</array>
<!-- Exported Type Declaration for MyExtension -->
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.directory</string>
</array>
<key>UTTypeDescription</key>
<string>Custom file extension for MyExtension files</string>
<key>UTTypeIconFiles</key>
<array>
<string>MyApp File Icon</string>
</array>
<key>UTTypeIdentifier</key>
<string>au.com.mycompany.myapp.MyExtension</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>myextension</string>
</array>
</dict>
</dict>
</array>
<!-- Imported Type Declaration for MyExtension -->
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.directory</string>
</array>
<key>UTTypeDescription</key>
<string>Custom file extension for MyExtension files</string>
<key>UTTypeIdentifier</key>
<string>au.com.mycompany.myapp.MyExtension</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>myextension</string>
</array>
</dict>
</dict>
</array>
I am seeking assistance in resolving this issue so that my application can properly recognize and open files with my custom extension, both via AirDrop and within the Files app. Any insights or suggestions would be greatly appreciated.
I'm trying to render a UIView to PDF, while maintaining text elements as actual text and not rasterizing them.
I'm using TextKit 2 backed UITextView and NSTextLayoutManager to provide the contents. However, no matter what I do, UITextView gets rasterized into a bitmap.
Here's the basic code:
let renderer = UIGraphicsPDFRenderer(bounds: pageRect, format: format)
let data = renderer.pdfData { (context) in
for page in self.pageViews {
context.beginPage()
let cgContext = context.cgContext
page.layer.render(in: cgContext)
}
}
A page view usually contains one UITextView, which uses somewhat advanced layout, so unfortunately I can't just toss it into a single NSAttributedString and draw into a CoreText context.
There's a hack to get UILabels to render themselves as non-rasterized text, and if I understand correctly, it works by just actually drawing them on the current context.
Interestingly, when providing UILabel view via NSTextAttachmentViewProvider to a text view using TextKit 2, the UILabels inside a text view won't get rasterized. In the image below, the paragraph is a bitmap, while the heading is real text.
This hinted that the actual text fragments are the ones that get rasterized when drawing, not the whole view, and I was right.
I can enumerate the text fragments and draw them directly on the context, which makes them remain as text rather than become a bitmap:
page.textView?.textLayoutManager?.enumerateTextLayoutFragments(from: location, options: [.ensuresLayout, .estimatesSize, .ensuresExtraLineFragment], using: { fragment in
let frame = fragment.layoutFragmentFrame
fragment.draw(at: frame.origin, in: cgContext)
return true
})
This causes other issues, because layout coordinates will be all over the place and not confined to the text view itself (and even more so for my custom NSTextLayoutFragment class). I can get around this, but my text attachments won't get drawn this way either, but display a skewed placeholder icon:
I can render them correctly on the context manually:
if fragment.textAttachmentViewProviders.count > 0 {
if let view = fragment.textAttachmentViewProviders.first?.view {
view.layer.render(in: cgContext)
return true
}
}
This renders them at 0, 0 though.
Edit: Changing bounds or frame for view/layer has no effect.
I'm wondering if there is a way to make UITextView and NSTextLayoutManager to draw their contents this way automatically, so the fragments would remain as text in the PDF, rather than become a bitmap? It seems weird that the text view doesn't do this by default like it does on macOS, especially as it appears to be entirely possible.
Or, if that's not possible, what's the correct way of drawing my text attachments when enumerating NSTextLayoutFragments?
I have been having intermittent Crashes but I still have no idea why that is happening.
Seems to happen right after I initialize a Controller from Storyboard.
crashReport.crash
Let me know if you have any inputs on fixing this crash. Thanks!!
UIDevice.orientationDidChangeNotification works as expected without calls to beginGeneratingDeviceOrientationNotifications() and endGeneratingDeviceOrientationNotifications() but the respective documentation for these two methods state:
You must call this method before attempting to get orientation data from the device.
and
You call this method after a previous call to the beginGeneratingDeviceOrientationNotifications() method.
Were they a requirement at one time and never deprecated?
Background:
We have an iOS app that supports a single window. We are using a UISceneDelegate. We do not support multiple windows or scenes.
Problem:
When a user mirrors the screen of their iPhone device, iOS automatically initializes a new scene with a non-interactive display role. For the time being, we would like to disable opting into this and instead simply mirror the existing device window.
Going through the docs, I haven't been able to find any way of doing this. All the docs appear to assume that once you start supporting UIScene, you should automatically support any screen size, aspect ratio or connected display.
In the Scenes Overview section, it claims that setting UIApplicationSupportsMultipleScenes to false will never create multiple windows, but I've confirmed under the debugger that this isn't true.
Any ideas?
Repro Steps:
Create an iOS app with a single window that supports UISceneDelegate
Launch the app on your iPhone (tested using iOS 17.3)
Turn on your Apple TV
From Control Center, tap the mirror icon (two small windows)
How to slove this problem? Any idea, bro?
Crash-TestEasy.log
I am a beginner to swift language and with the help of apple book, I was typing this code on switching colours using buttons.
then in this line: if redswitch.isOn {
it is showing this fatal error. What to do I have no idea. Please help me out.
Here's the code:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var colourView: UIView!
@IBOutlet weak var redswitch: UISwitch!
@IBOutlet weak var greenswitch: UISwitch!
@IBOutlet weak var blueswitch: UISwitch!
override func viewDidLoad() {
super.viewDidLoad()
updateColor()
// Do any additional setup after loading the view.
}
@IBAction func switchChanged(_sender: UISwitch){
updateColor()
}
func updateColor() {
var red: CGFloat = 0
var green: CGFloat = 0
var blue: CGFloat = 0
if redswitch.isOn {
red = 1
}
if greenswitch.isOn {
green = 1
}
if blueswitch.isOn {
blue = 1
}
let color = UIColor(red: red, green: green,
blue: blue, alpha: 1)
colourView.backgroundColor = color
}
}
I have been having issue with tableview changing its content offset when disabling the scroll on the button click. Is this the expected behaviour?
This is with Xcode 15 and iOS 17.