监控 Swift 中的钥匙串项更改
Monitoring Keychain item changes in Swift
Keychain Services API 允许钥匙串中的 adding/updating/deleting 项。但是,它似乎不包含任何用于监视特定钥匙串项的更改的机制。
我的应用程序正在钥匙串中存储一个值,如果该值被用户或其他进程更改,我想收到通知。这样的事情可能吗,还是我只需要定期轮询钥匙串项并自己检查更改?
这里有 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
Keychain Services API 允许钥匙串中的 adding/updating/deleting 项。但是,它似乎不包含任何用于监视特定钥匙串项的更改的机制。
我的应用程序正在钥匙串中存储一个值,如果该值被用户或其他进程更改,我想收到通知。这样的事情可能吗,还是我只需要定期轮询钥匙串项并自己检查更改?
这里有 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