Posts

Post not yet marked as solved
0 Replies
358 Views
In iOS 15, the following actions have been added to UIResponderStandardEditActions: - (void)pasteAndMatchStyle:(nullable id)sender API_AVAILABLE(ios(15.0)); - (void)pasteAndGo:(nullable id)sender API_AVAILABLE(ios(15.0)); - (void)pasteAndSearch:(nullable id)sender API_AVAILABLE(ios(15.0)); In https://developer.apple.com/wwdc21/10059 it is explained that these additional actions are specifically meant to avoid the "Copy & Paste Banner" that notifies the user that the app accessed the pasteboard. Since these are user initiated actions, the OS now knows that the intent was to paste so there is no need to notify the user. However, I cannot get this to work. I tried to do the following: class ViewController: UIViewController { @IBOutlet weak var textField: UITextField! override func viewDidLoad() { super.viewDidLoad() let item = UIMenuItem(title: "Paste & Go", action: #selector(pasteAndGo(_:))) UIMenuController.shared.menuItems = [item] } override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool { if action == #selector(pasteAndGo(_:)) { return true } return super.canPerformAction(action, withSender: sender) } override func pasteAndGo(_ sender: Any?) { textField.pasteAndGo(sender) } } Basically, I add it as a custom item to the UIMenuController, announce that I can handle pasteAndGo(_:) and then delegate it to the UITextField when the menu item is selected. The menu item shows up, but when selected, it causes an exception telling me that UITextField does not respond to the pasteAndGo: selector: Thread 1: "-[UITextField pasteAndGo:]: unrecognized selector sent to instance 0x14d813800" I don't understand this part. Isn't pasteAndGo(_:) supposed to be aliased to paste(_:) inside the UITextField? I thought that since these are aliases, we can get the same behaviour (text is pasted) but now we know in our actions what the actual intent was so that we can act on that accordingly. I've tried to set the keyboard type to "Web Search" and the Return Key to "Go" but that also made no difference. Has anyone made this work? I'm starting to think that this may not have actually shipped in iOS 15.
Posted Last updated
.
Post not yet marked as solved
1 Replies
260 Views
In the WWDC 2020 session "Keeping your Complication up to date" the following is said: As we said earlier, fifty of these are allowed per watch, per day. I would like to understand if this means globally for all applications combined or whether that is in the context of a single application. In other words, if I have 3 different applications on my watch that all shows a complication that is updated through complication pushes, will these 3 apps compete for those 50 pushes in total? Does anyone know?
Posted Last updated
.
Post not yet marked as solved
0 Replies
242 Views
I have a simple watchOS 6.2.8 SwiftUI application in which I present a list of messages to the user. These messages are modelled as classes and have a title, body and category name. I also have a Category object which is a view on these messages that only shows a specific category name. class Message: Identifiable { 		let identifier: String 		let date: Date 		let title: String 		let body: String 		let category: String 		 		var id: String { 				identifier 		} 		init(identifier: String, date: Date, title: String, body: String, category: String) { 				self.identifier = identifier 				self.date = date 				self.title = title 				self.body = body 				self.category = category 		} } class Category: ObservableObject, Identifiable { 		let name: String 		@Published var messages: [Message] = [] 		 		var id: String { 				name 		} 		init(name: String, messages: [Message] = []) { 				self.name = name 				self.messages = messages 		} } Category itself is an @ObservableObject and publishes messages, so that when a category gets updated (like in the background), the view that is displaying the category message list will also update. (This works great) To store these messages I have a simple MessageStore, which is an @ObservableObject that looks like this: class MessageStore: ObservableObject { 		@Published var messages: [Message] = [] 		@Published var categories: [Category] = [] 		static let sharedInstance = MessageStore() 		func insert(message: Message) throws { ... mutage messages and categories ... } 		func delete(message: Message) throws { ... mutage messages and categories ... } } (For simplicity I use a singleton, because there are problems with environment objects not being passed properly on watchOS) The story keeps messages and categories in sync. When a new Message is added that has a category name set, it will also create or update a Category object in the categories list. In my main view I present two things: An All Messages NavigationLink that goes to a view to display all messages For each Category I display a NavigationLink that goes to a view to display messages just in that specific category. This all works, amazingly. But there is one really odd thing happening that I do not understand. (First SwiftUI project) When I go into the All Messages list and delete all messages containing to a specific category, something unexpected happen when I navigate back to the main view. First I observe that the category is properly removed from the list. But then, the main view automatically quickly navigates to the All Messages list and then back. The last part is driving me .. crazy .. I don't understand why this is happening. From a data perspective everyting looks good - the messages have been deleted and the category too. The final UI state, after the automagical navigation, also looks good - the message count for All Messages is correct and the category with now zero messages is not shown in the list anymore. Full project at https://github.com/st3fan/LearningSwiftUI/tree/master/MasterDetail
Posted Last updated
.