如何订阅PKPassLibraryNotificationName

问题描述 投票:0回答:1

我需要观察https://developer.apple.com/documentation/passkit/pkpasslibrarynotificationname中指定的.PKPassLibraryDidChange和.PKPassLibraryRemotePaymentPassesDidChange通知,>

但是它们不是NSNotification.Name的子类,所以

let observer = NotificationCenter.default.addObserver(forName: PKPassLibraryNotificationName.PKPassLibraryDidChange, object: nil, queue: nil) { notification in  
     ...  
} 

不编译。

是否需要进行其他导入才能在NotificationCenter上观察PKPassLibraryNotificationName

[我需要观察https://developer.apple.com/documentation/passkit / ...中指定的.PKPassLibraryDidChange和.PKPassLibraryRemotePaymentPassesDidChange通知]

ios swift notificationcenter
1个回答
0
投票
要回答您的实际问题,Notification.Name只是一个字符串。您可以这样创建通知名称:

let notification = NSNotification.Name(rawValue: PKPassLibraryNotificationName.PKPassLibraryDidChange.rawValue) NotificationCenter.default.addObserver(forName: notification, object: myPassLibrary, queue: nil) { (notification) in // do something here }

© www.soinside.com 2019 - 2024. All rights reserved.