Posts

Post not yet marked as solved
1 Replies
1.3k Views
I am trying to implement Quick Notes through SwiftUI, rather than UIKit or AppKit. I am unsure if the behaviour below is expected, or due to a bug. I have already successfully implemented NSUserActivity for Handoff, Spotlight and Siri Reminders, using the .userActivity() view modifier. These NSUserActivity instances use the NSUserActivity.userInfo dictionary to store and correctly restore the content through the .onContinueUserActivity(perform: ) methods. Quick Notes requires using the .persistentIdentifier or .targetContentIdentifier properties, rather than the .userInfo dictionary alone. However, when I set these either of these to unique identifiers using the code below, they are not correctly stored within the useractivity. MyView() .userActivity(ActivityString, updateUserActivity) private func updateUserActivity(_ activity: NSUserActivity) {     activity.isEligibleForSearch = true     activity.isEligibleForHandoff = true     activity.title = "Title"     activity.targetContentIdentifier = myItemUniqueID     activity.persistentIdentifier = myItemUniqueID     activity.userInfo = ["id": myItemUniqueID]     print(activity.targetContentIdentifier) // Correctly prints     print(activity.persistentIdentifier) // Correctly prints     print(activity.userInfo) // Correctly prints     } The identifiers print correctly when setting the user activity above. However, when restoring the user activity (tested through Handoff and Spotlight Search), the targetContentIdentifier and persistentIdentifier strings are empty. MyView()     .onContinueUserActivity(ActivityString, perform: continueUserActivity) private func continueUserActivity(_ activity: NSUserActivity) {     print(activity.persistentIdentifier) // Nil     print(activity.targetContentIdentifier) // Nil     print(activity.userInfo) // Correctly prints     } Is there something else I must do, or is this unexpected behaviour?
Posted Last updated
.
Post not yet marked as solved
4 Replies
9.7k Views
I would love my SwiftUI views to support the new modifiers in iOS 14 (e.g. .navigationTitle), but still run on iOS 13 (e.g. using deprecated .navigationBarTitle). What is the best way to add conditional #if available code for view modifiers? The only way I can find to do it is by extracting every subview, and putting #if available blocks around every view declaration — this seems very tedious, as I am redefining each view twice. E.g. struct SettingsView: View {     var body: some View {         NavigationView {             if #available(iOS 14.0, *) {                 SettingsContentView()                     .navigationTitle("Settings")             } else {                 SettingsContentView()                     .navigationBarTitle("Settings")             }         }     } } Is there a better way to just add conditional code only around the modifiers? Thanks in advance.
Posted Last updated
.
Post not yet marked as solved
0 Replies
508 Views
When using UIKit, the UIBarButtonItems automatically get support for the highlight hover effect when using a pointer in iOS 13.4+. After updating some views to use SwiftUI, the equivalent NavigationBarItem modifiers do not have a highlight hover effect. Is this a bug, not supported, or implemented in a different way?
Posted Last updated
.