APP通过代码从钥匙串获取不到证书

通过配置描述文件安装到设备的客户端证书,然后通过代码获取有效身份,为什么获取不到呢?

查询代码:

- (SecIdentityRef)loadClientIdentityFromKeychain {
    SecIdentityRef identity = NULL;
    
    // 构建查询条件
    NSDictionary *query = @{
        (__bridge id)kSecClass: (__bridge id)kSecClassIdentity,
        (__bridge id)kSecReturnRef: @YES,
        (__bridge id)kSecMatchLimit: (__bridge id)kSecMatchLimitOne,
    };
    
    // 执行钥匙串查询
    OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, (CFTypeRef *)&identity);

    if (status != errSecSuccess) {
        NSLog(@"钥匙串查询失败,错误码: %d", (int)status);
        return NULL;
    }
    
    
    return identity;
}


iPhone 13, iOS 26

发布日期 2026年1月21日 下午9:19

回复

没有回复。

APP通过代码从钥匙串获取不到证书

欢迎来到 Apple 支持社区
Apple 客户在其产品方面互相帮助的论坛。使用您的 Apple 帐户开始畅游其中吧!!