application:continueUserActivity:restorationHandler: 使用切换时未被调用
application:continueUserActivity:restorationHandler: is not getting called when using handoff
我在我的测试设备(不使用模拟器)和 SwiftUI
上使用最新版本的 Xcode、macOS、iOS
我的 UI 使用 SwiftUI 和我的 UserActivity DelegateHandler:
struct UserActivityDelegateObserver: UIViewRepresentable {
@Binding var textData: String
func makeUIView(context: Context) -> UIView { return UIView() }
func updateUIView(_ uiView: UIView, context: Context) {
context.coordinator.userActivity?.needsSave = true
}
func makeCoordinator() -> Coordinator {
Coordinator(textData: _textData)
}
class Coordinator: UIResponder, NSUserActivityDelegate {
@Binding var textData: String
init(textData: Binding<String>) {
self._textData = textData
super.init()
self.userActivity = NSUserActivity(activityType: "com.domain.appname.activity")
self.userActivity!.title = "My Activity"
self.userActivity!.userInfo = ["Key": textData.wrappedValue]
self.userActivity!.isEligibleForHandoff = true
self.userActivity!.becomeCurrent()
}
override func updateUserActivityState(_ activity: NSUserActivity) {
activity.addUserInfoEntries(from: ["Key": textData])
super.updateUserActivityState(activity)
}
}
}
struct ContentView: View {
@State var textData: String = "Placeholder"
var body: some View {
NavigationView {
ZStack {
UserActivityDelegateObserver(textData: $textData)
Form {
Section {
TextField("Placeholder", text: $textData)
}
}
}
.navigationBarTitle("Title", displayMode: .inline)
}
}
}
在我的 appdelegate
里面:
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
print("this is not getting called")
return true
}
当我在一台设备上启动该应用程序并使用我的另一台设备进入该菜单(双击主页按钮时)并单击屏幕底部我的测试应用程序的切换符号时,该应用程序得到已启动但函数 application:continueUserActivity:restorationHandler:
从未被调用,因此我无法继续,它显示了通过单击启动应用程序时的标准行为。知道这是为什么吗?
这可能是一个错误 报告了同样的问题但仍然没有答案所以我认为这可能是 Xcode.
测试版的错误
我在我的测试设备(不使用模拟器)和 SwiftUI
上使用最新版本的 Xcode、macOS、iOS我的 UI 使用 SwiftUI 和我的 UserActivity DelegateHandler:
struct UserActivityDelegateObserver: UIViewRepresentable {
@Binding var textData: String
func makeUIView(context: Context) -> UIView { return UIView() }
func updateUIView(_ uiView: UIView, context: Context) {
context.coordinator.userActivity?.needsSave = true
}
func makeCoordinator() -> Coordinator {
Coordinator(textData: _textData)
}
class Coordinator: UIResponder, NSUserActivityDelegate {
@Binding var textData: String
init(textData: Binding<String>) {
self._textData = textData
super.init()
self.userActivity = NSUserActivity(activityType: "com.domain.appname.activity")
self.userActivity!.title = "My Activity"
self.userActivity!.userInfo = ["Key": textData.wrappedValue]
self.userActivity!.isEligibleForHandoff = true
self.userActivity!.becomeCurrent()
}
override func updateUserActivityState(_ activity: NSUserActivity) {
activity.addUserInfoEntries(from: ["Key": textData])
super.updateUserActivityState(activity)
}
}
}
struct ContentView: View {
@State var textData: String = "Placeholder"
var body: some View {
NavigationView {
ZStack {
UserActivityDelegateObserver(textData: $textData)
Form {
Section {
TextField("Placeholder", text: $textData)
}
}
}
.navigationBarTitle("Title", displayMode: .inline)
}
}
}
在我的 appdelegate
里面:
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
print("this is not getting called")
return true
}
当我在一台设备上启动该应用程序并使用我的另一台设备进入该菜单(双击主页按钮时)并单击屏幕底部我的测试应用程序的切换符号时,该应用程序得到已启动但函数 application:continueUserActivity:restorationHandler:
从未被调用,因此我无法继续,它显示了通过单击启动应用程序时的标准行为。知道这是为什么吗?
这可能是一个错误