unity-ios钥匙串Keychain
立即下载
资源介绍:
1、按压缩包内路径添加至unity工程,若工程内划分了程序集,可以自行在Assets\Plugins\iOS\Keychain路径下创建程序集
2、打开KeychainWrapper.m文件,将appStoreTeamID和accessGroup设置为自己的AppStore Team ID
NSString *appStoreTeamID = @"11223344";
NSString *accessGroup = @"11223344.SHARED";
3、使用方法:
var keychainWrapper = new KeychainWrapper();
keychainWrapper.SetStringForKey("key", "value");
var = keychainWrapper.GetStringForKey("key")
#import
#if !__has_feature(nullability)
#define NS_ASSUME_NONNULL_BEGIN
#define NS_ASSUME_NONNULL_END
#define nullable
#define nonnull
#define null_unspecified
#define null_resettable
#define __nullable
#define __nonnull
#define __null_unspecified
#endif
#if __has_extension(objc_generics)
#define UIC_KEY_TYPE
#define UIC_CREDENTIAL_TYPE *>
#else
#define UIC_KEY_TYPE
#define UIC_CREDENTIAL_TYPE
#endif
NS_ASSUME_NONNULL_BEGIN
extern NSString * const KeychainStoreErrorDomain;
typedef NS_ENUM(NSInteger, KeychainStoreErrorCode) {
KeychainStoreErrorInvalidArguments = 1,
};
typedef NS_ENUM(NSInteger, KeychainStoreItemClass) {
KeychainStoreItemClassGenericPassword = 1,
KeychainStoreItemClassInternetPassword,
};
typedef NS_ENUM(NSInteger, KeychainStoreProtocolType) {
KeychainStoreProtocolTypeFTP = 1,
KeychainStoreProtocolTypeFTPAccount,
KeychainStoreProtocolTypeHTTP,
KeychainStoreProtocolTypeIRC,
KeychainStoreProtocolTypeNNTP,
KeychainStoreProtocolTypePOP3,
KeychainStoreProtocolTypeSMTP,
KeychainStoreProtocolTypeSOCKS,
KeychainStoreProtocolTypeIMAP,
KeychainStoreProtocolTypeLDAP,
KeychainStoreProtocolTypeAppleTalk,
KeychainStoreProtocolTypeAFP,
KeychainStoreProtocolTypeTelnet,
KeychainStoreProtocolTypeSSH,
KeychainStoreProtocolTypeFTPS,
KeychainStoreProtocolTypeHTTPS,
KeychainStoreProtocolTypeHTTPProxy,
KeychainStoreProtocolTypeHTTPSProxy,
KeychainStoreProtocolTypeFTPProxy,
KeychainStoreProtocolTypeSMB,
KeychainStoreProtocolTypeRTSP,
KeychainStoreProtocolTypeRTSPProxy,
KeychainStoreProtocolTypeDAAP,
KeychainStoreProtocolTypeEPPC,
KeychainStoreProtocolTypeNNTPS,
KeychainStoreProtocolTypeLDAPS,
KeychainStoreProtocolTypeTelnetS,
KeychainStoreProtocolTypeIRCS,
KeychainStoreProtocolTypePOP3S,
};
typedef NS_ENUM(NSInteger, KeychainStoreAuthenticationType) {
KeychainStoreAuthenticationTypeNTLM = 1,
KeychainStoreAuthenticationTypeMSN,
KeychainStoreAuthenticationTypeDPA,
KeychainStoreAuthenticationTypeRPA,
KeychainStoreAuthenticationTypeHTTPBasic,
KeychainStoreAuthenticationTypeHTTPDigest,
KeychainStoreAuthenticationTypeHTMLForm,
KeychainStoreAuthenticationTypeDefault,
};
typedef NS_ENUM(NSInteger, KeychainStoreAccessibility) {
KeychainStoreAccessibilityWhenUnlocked = 1,
KeychainStoreAccessibilityAfterFirstUnlock,
KeychainStoreAccessibilityAlways,
KeychainStoreAccessibilityWhenPasscodeSetThisDeviceOnly
__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0),
KeychainStoreAccessibilityWhenUnlockedThisDeviceOnly,
KeychainStoreAccessibilityAfterFirstUnlockThisDeviceOnly,
KeychainStoreAccessibilityAlwaysThisDeviceOnly,
}
__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_4_0);
typedef NS_ENUM(NSInteger, KeychainStoreAuthenticationPolicy) {
KeychainStoreAuthenticationPolicyUserPresence = kSecAccessControlUserPresence,
};
@interface KeychainStore : NSObject
@property (nonatomic, readonly) KeychainStoreItemClass itemClass;
@property (nonatomic, readonly, nullable) NSString *service;
@property (nonatomic, readonly, nullable) NSString *accessGroup;
@property (nonatomic, readonly, nullable) NSURL *server;
@property (nonatomic, readonly) KeychainStoreProtocolType protocolType;
@property (nonatomic, readonly) KeychainStoreAuthenticationType authenticationType;
@property (nonatomic) KeychainStoreAccessibility accessibility;
@property (nonatomic, readonly) KeychainStoreAuthenticationPolicy authenticationPolicy
__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0);
@property (nonatomic) BOOL synchronizable;
@property (nonatomic, nullable) NSString *authenticationPrompt
__OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_8_0);
@property (nonatomic, readonly, nullable) NSArray UIC_KEY_TYPE *allKeys;
@property (nonatomic, readonly, nullable) NSArray *allItems;
+ (NSString *)defaultService;
+ (void)setDefaultService:(NSString *)defaultService;
+ (KeychainStore *)keychainStore;
+ (KeychainStore *)keychainStoreWithService:(nullable NSString *)service;
+ (KeychainStore *)keychainStoreWithService:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
+ (KeychainStore *)keychainStoreWithServer:(NSURL *)server protocolType:(KeychainStoreProtocolType)protocolType;
+ (KeychainStore *)keychainStoreWithServer:(NSURL *)server protocolType:(KeychainStoreProtocolType)protocolType authenticationType:(KeychainStoreAuthenticationType)authenticationType;
- (instancetype)init;
- (instancetype)initWithService:(nullable NSString *)service;
- (instancetype)initWithService:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
- (instancetype)initWithServer:(NSURL *)server protocolType:(KeychainStoreProtocolType)protocolType;
- (instancetype)initWithServer:(NSURL *)server protocolType:(KeychainStoreProtocolType)protocolType authenticationType:(KeychainStoreAuthenticationType)authenticationType;
+ (nullable NSString *)stringForKey:(NSString *)key;
+ (nullable NSString *)stringForKey:(NSString *)key service:(nullable NSString *)service;
+ (nullable NSString *)stringForKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
+ (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key;
+ (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key service:(nullable NSString *)service;
+ (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
+ (nullable NSData *)dataForKey:(NSString *)key;
+ (nullable NSData *)dataForKey:(NSString *)key service:(nullable NSString *)service;
+ (nullable NSData *)dataForKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
+ (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key;
+ (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key service:(nullable NSString *)service;
+ (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
- (BOOL)contains:(nullable NSString *)key;
- (BOOL)setString:(nullable NSString *)string forKey:(nullable NSString *)key;
- (BOOL)setString:(nullable NSString *)string forKey:(nullable NSString *)key label:(nullable NSString *)label comment:(nullable NSString *)comment;
- (nullable NSString *)stringForKey:(NSString *)key;
- (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key;
- (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key label:(nullable NSString *)label comment:(nullable NSString *)comment;
- (nullable NSData *)dataForKey:(NSString *)key;
+ (BOOL)removeItemForKey:(NSString *)key;
+ (BOOL)removeItemForKey:(NSString *)key service:(nullable NSString *)service;
+ (BOOL)removeItemForKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
+ (BOOL)removeAllItems;
+ (BOOL)removeAllItemsForService:(nullable NSString *)service;
+ (BOOL)removeAllItemsForService:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
- (BOOL)removeItemForKey:(NSString *)key;
- (BOOL)removeAllItems;
- (nullable NSString *)objectForKeyedSubscript:(NSString *)key;
- (void)setObject:(nullable NSString *)obj forKeyedSubscript:(NSString *)key;
+ (nullable NSArray UIC_KEY_TYPE *)allKeysWithItemClass:(KeychainStoreItemClass)itemClass;
- (nullable NSArray UIC_KEY_TYPE *)allKeys;
+ (nullable NSArray *)allItemsWithItemClass:(KeychainStoreItemClass)itemClass;
- (nullable NSArray *)allItems;
- (void)setAccessibility:(KeychainStoreAccessibility)accessibility authenticationPolicy:(KeychainStoreAuthenticationPolicy)authenticationPolicy
__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0);
#if TARGET_OS_IOS
- (void)sharedPasswordWithCompletion:(nullable void (^)(NSStri