In iOS 13 there seems to be a bug. When the app is using a view controller-based status bar appearance by setting <key>UIViewControllerBasedStatusBarAppearance</key> <true/>in info.plist and overriding prefersStatusBarHidden in some ViewControllers subclasses with returning true for some ViewControllers and returning false for some other ViewController subclasses than the NavigationBar gets misplaced on devices like iPhone 6, 7 or 8.Is there a workaround for this?Is this a known issue?On iOS 12 this problem does not occur.Here is an example Xcode project where you can see this bug:https://github.com/1010011010/iOS13StatusBar
Post
Replies
Boosts
Views
Activity
Is it possible to convince the DateComponentsFormatter that 30 days are also one month as 31 days are?The backend to which our app is connected to sends a duration of 30 days and this should be displayed as "1 month" duration on the UI.This is the code I used:let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.second, .minute, .hour, .day, .weekOfMonth, .month, .year]
formatter.unitsStyle = .full
formatter.maximumUnitCount = 1
formatter.string(from: duration)And this will be formatted to "4 weeks" when the duration is 30 days and formatted to "1 month" when duration is 31 days.
The code below renders a view with a navigation bar. A plus button is placed on the navigation bar which opens a sheet. After closing this sheet view programmatically the plus button of the first view won't react anymore. Is this an iOS bug or is the code incorrect?import SwiftUI
struct ContentView: View {
@State var isAddPresented = false
var body: some View {
NavigationView {
Text("Tap plus to add item")
.navigationBarTitle("Main Screen Title")
.navigationBarItems(trailing:
Button(action: {
self.isAddPresented = true
}) {
Image(systemName: "plus")
}
)
.sheet(isPresented: $isAddPresented,
onDismiss: {
self.isAddPresented = false
}) {
NavigationView {
Text("Tap on save")
.navigationBarTitle("Add something")
.navigationBarItems(leading: Button(action: {self.isAddPresented = false}, label: {Text("Save")}))
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Since some weeks we have app crashes but I'm unabled to reproduce it. Does someone have an idea how this can happen and where to look?
Incident Identifier: 75DB8F4A-50BB-4943-A874-D1560B6DC863
Hardware Model:			iPhone11,2
Version:						 6.2.62.2 (6.2.62)
AppStoreTools:			 12B45a
AppVariant:					1:iPhone11,2:13
Code Type:					 ARM-64 (Native)
Role:								Foreground
Parent Process:			launchd [1]
Date/Time:					 2020-12-08 21:13:14.5364 +0100
Launch Time:				 2020-12-08 21:13:09.6886 +0100
OS Version:					iPhone OS 14.2 (18B92)
Release Type:				User
Baseband Version:		3.01.01
Report Version:			104
Exception Type:	EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:	EXC_CORPSE_NOTIFY
Triggered by Thread:	0
Last Exception Backtrace:
0	 CoreFoundation								 0x1a7804878 __exceptionPreprocess + 220 (NSException.m:199)
1	 libobjc.A.dylib							 0x1bbd5ac50 objc_exception_throw + 60 (objc-exception.mm:565)
2	 CoreFoundation								 0x1a770a000 +[NSException raise:format:arguments:] + 100 (NSException.m:146)
3	 Foundation										 0x1a8a9b91c -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 132 (NSException.m:231)
4	 UIKitCore										 0x1aa1c0720 __58-[UIApplication _applicationOpenURLAction:payload:origin:]_block_invoke + 1084 (UIApplication.m:7060)
5	 UIKitCore										 0x1aa1c00c0 -[UIApplication _applicationOpenURLAction:payload:origin:] + 912 (UIApplication.m:7106)
6	 UIKitCore										 0x1aa1cd700 -[UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion:] + 5048 (UIApplication.m:10163)
7	 UIKitCore										 0x1a963c614 -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 492 (UIScene.m:1118)
8	 UIKitCore										 0x1a963d7dc -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 248 (UIScene.m:1380)
9	 UIKitCore										 0x1a9cb1d0c -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 492 (UIApplicationSceneClientAgent.m:80)
10	FrontBoardServices						 0x1b6b0dd54 -[FBSScene updater:didUpdateSettings:withDiff:transitionContext:completion:] + 484 (FBSScene.m:547)
11	FrontBoardServices						 0x1b6b3a5c4 __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke_2 + 152 (FBSWorkspaceScenesClient.m:533)
12	FrontBoardServices						 0x1b6b1c560 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 240 (FBSWorkspace.m:355)
13	FrontBoardServices						 0x1b6b3a4f0 __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke + 396 (FBSWorkspaceScenesClient.m:532)
14	libdispatch.dylib						 0x1a73f8db0 _dispatch_client_callout + 20 (object.m:559)
15	libdispatch.dylib						 0x1a73fc738 _dispatch_block_invoke_direct + 268 (queue.c:468)
16	FrontBoardServices						 0x1b6b61310 FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 48 (FBSSerialQueue.m:184)
17	FrontBoardServices						 0x1b6b60fa0 -[FBSSerialQueue _targetQueue_performNextIfPossible] + 448 (FBSSerialQueue.m:227)
18	FrontBoardServices						 0x1b6b614f4 -[FBSSerialQueue _performNextFromRunLoopSource] + 32 (FBSSerialQueue.m:258)
19	CoreFoundation								 0x1a778076c CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 28 (CFRunLoop.c:1967)
20	CoreFoundation								 0x1a7780668 __CFRunLoopDoSource0 + 208 (CFRunLoop.c:2011)
21	CoreFoundation								 0x1a777f960 __CFRunLoopDoSources0 + 268 (CFRunLoop.c:2048)
22	CoreFoundation								 0x1a7779a8c __CFRunLoopRun + 824 (CFRunLoop.c:2925)
23	CoreFoundation								 0x1a777921c CFRunLoopRunSpecific + 600 (CFRunLoop.c:3242)
24	GraphicsServices							 0x1be7f8784 GSEventRunModal + 164 (GSEvent.c:2259)
25	UIKitCore										 0x1aa1b2200 -[UIApplication _run] + 1072 (UIApplication.m:3266)
26	UIKitCore										 0x1aa1b7a74 UIApplicationMain + 168 (UIApplication.m:4738)
28	libdyld.dylib								 0x1a74396c0 start + 4
I've created a view with a TextField and an EditButton. When I open this view in a fullScreenCover with the editMode active than the input text disappears when the Done-Button is tapped.
This behavior is appearing when a @ObservedObject is used. When a @State variable is used for the TextField then everything is fine.
This is the view
Swift
struct ProfileView: View {
@ObservedObject
var viewModel = ProfileViewModel()
@Environment(\.editMode) var editMode
@State
var name = ""
var body: some View {
VStack {
Text("@State")
TextField("TextField", text: $name)
.disabled(editMode?.wrappedValue == .inactive)
Text("@ObservedObject")
TextField("TextField", text: $viewModel.name)
.disabled(editMode?.wrappedValue == .inactive)
Spacer()
}
.padding()
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
EditButton()
}
}
}
}
Using
Swift
class ProfileViewModel: ObservableObject {
@Published var name: String = ""
}
This is the view which is presenting
Swift
struct ContentView: View {
@State
var isPresentingEmtpyProfile: Bool = false
var body: some View {
NavigationView {
List {
NavigationLink(destination: ProfileView()) {
Text("ProfileView")
}
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {
isPresentingEmtpyProfile = true
}) {
Image(systemName: "plus")
}
}
}
.navigationBarTitle("Navigation", displayMode: .inline)
.fullScreenCover(isPresented: $isPresentingEmtpyProfile) {
NewProfileViewWithNavigation(isPresentingEmptyProfile: $isPresentingEmtpyProfile)
}
}
}
}
extension ContentView {
struct NewProfileViewWithNavigation: View {
@State
private var editMode = EditMode.active
@Binding
var isPresentingEmptyProfile: Bool
var body: some View {
NavigationView {
ProfileView()
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button(action: {
isPresentingEmptyProfile = false
}) {
Text("Close")
}
}
ToolbarItem(placement: .principal) {
Text("New Profile")
}
}
.environment(\.editMode, $editMode)
}
}
}
}
Does anyone have an idea why this is happening?
We created a view which is a bit comparable to the view of a contact in the iOS Contacts app. At the top there are input fields which can't be deleted and at the bottom is a long list of items which can be deleted.
I was wondering if is there a List with an ondelete() functionality but without separators?
I just created a SwiftUI project in Xcode 12.5 (12E262) and changed my main App class to
import SwiftUI
class AppDelegate: UIResponder, UIApplicationDelegate {
func applicationDidFinishLaunching(_ application: UIApplication) {
print("applicationDidFinishLaunching")
}
func applicationDidBecomeActive(_ application: UIApplication) {
print("applicationDidBecomeActive")
}
func applicationDidEnterBackground(_ application: UIApplication) {
print("applicationDidEnterBackground")
}
func applicationWillEnterForeground(_ application: UIApplication) {
print("applicationWillEnterForeground")
}
func applicationWillTerminate(_ application: UIApplication) {
print("applicationWillTerminate")
}
}
@main
struct SwiftUIAppDelegateTestsApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
No app delegate method is called.
Should the App Delegate listed anywhere else e.g. in the build settings or info plist?
I'm wondering which way I should go in my current app project.
It is an app where the user can take a photo and place multiple 2D vector images on that photo. Some vector images are showing angles between lines. The user can interact with the vectors to change the angels to make some measurements on the photo.
So you have multiple layers of vector images upon a photo. You can also pinch to zoom to have better control to set accurate vectors/angles.
The user can choose the layer to interact with so I need to have control of all gesture recognizers and for example deactivate the pinch gestures on the scroll view.
I'm wondering which technology I should use 🤔 SwiftUI, UIKit or CoreGraphics?
Does somebody have some recommendations?
This code to write UIImage data as heic works in iOS simulator with iOS < 17.5
import AVFoundation
import UIKit
extension UIImage {
public var heic: Data? { heic() }
public func heic(compressionQuality: CGFloat = 1) -> Data? {
let mutableData = NSMutableData()
guard let destination = CGImageDestinationCreateWithData(mutableData, AVFileType.heic as CFString, 1, nil),
let cgImage = cgImage else {
return nil
}
let options: NSDictionary = [
kCGImageDestinationLossyCompressionQuality: compressionQuality,
kCGImagePropertyOrientation: cgImageOrientation.rawValue,
]
CGImageDestinationAddImage(destination, cgImage, options)
guard CGImageDestinationFinalize(destination) else { return nil }
return mutableData as Data
}
public var isHeicSupported: Bool {
(CGImageDestinationCopyTypeIdentifiers() as! [String]).contains("public.heic")
}
var cgImageOrientation: CGImagePropertyOrientation { .init(imageOrientation) }
}
extension CGImagePropertyOrientation {
init(_ uiOrientation: UIImage.Orientation) {
switch uiOrientation {
case .up: self = .up
case .upMirrored: self = .upMirrored
case .down: self = .down
case .downMirrored: self = .downMirrored
case .left: self = .left
case .leftMirrored: self = .leftMirrored
case .right: self = .right
case .rightMirrored: self = .rightMirrored
@unknown default:
fatalError()
}
}
}
But with iOS 17.5 simulator it seems to be broken.
The call of CGImageDestinationFinalize
writes this error into the console:
writeImageAtIndex:962: *** CMPhotoCompressionSessionAddImage: err = kCMPhotoError_UnsupportedOperation [-16994] (codec: 'hvc1')
On physical devices it still seems to work.
Is there any known workaround for the iOS simulator?