监控Swift中的钥匙链项目更改

监控Swift中的钥匙链项目更改,swift,macos,keychain,Swift,Macos,Keychain,允许添加/更新/删除钥匙链中的项目。然而,它似乎没有包含任何机制来监视特定的键链项的更改 我的应用程序正在密钥链中存储一个值,如果该值被用户或其他进程更改,我希望收到通知。这是可能的,还是我只需要定期轮询密钥链项目并亲自检查更改?以下是安全框架的API供您使用 /** @function SecKeychainAddCallback @abstract Registers your keychain event callback function @param callb

允许添加/更新/删除钥匙链中的项目。然而,它似乎没有包含任何机制来监视特定的键链项的更改


我的应用程序正在密钥链中存储一个值,如果该值被用户或其他进程更改,我希望收到通知。这是可能的,还是我只需要定期轮询密钥链项目并亲自检查更改?

以下是安全框架的API供您使用

/**
    @function SecKeychainAddCallback
    @abstract Registers your keychain event callback function
    @param callbackFunction A pointer to your keychain event callback function, described in SecKeychainCallback. You indicate the type of keychain events you want to receive by passing a bit mask of the desired events in the eventMask parameter.
    @param eventMask A bit mask indicating the keychain events that your application wishes to be notified of. See SecKeychainEventMask for a description of this bit mask. The Keychain Manager tests this mask to determine the keychain events that you wish to receive, and passes these events in the keychainEvent parameter of your callback function. See SecKeychainEvent for a description of these events.
    @param userContext A pointer to application-defined storage that will be passed to your callback function. Your application can use this to associate any particular call of SecKeychainAddCallback with any particular call of your keychain event callback function.
    @result A result code.  See "Security Error Codes" (SecBase.h).
*/
public func SecKeychainAddCallback(_ callbackFunction: SecKeychainCallback, 
    _ eventMask: SecKeychainEventMask, 
    _ userContext: UnsafeMutableRawPointer?) -> OSStatus

这正是我想要的。谢谢