Access App Identifier Prefix programmatically

前端 未结 5 812
死守一世寂寞
死守一世寂寞 2020-11-28 20:15

How can I access the Bundle Seed ID/Team ID/App Identifier Prefix string programmatically? (These are all the same thing as far as I can tell).

I am using the UICKe

5条回答
  •  再見小時候
    2020-11-28 21:13

    Here is the Swift version of @David H answer:

    static func bundleSeedID() -> String? {
            let queryLoad: [String: AnyObject] = [
                kSecClass as String: kSecClassGenericPassword,
                kSecAttrAccount as String: "bundleSeedID" as AnyObject,
                kSecAttrService as String: "" as AnyObject,
                kSecReturnAttributes as String: kCFBooleanTrue
            ]
    
            var result : AnyObject?
            var status = withUnsafeMutablePointer(to: &result) {
                SecItemCopyMatching(queryLoad as CFDictionary, UnsafeMutablePointer($0))
            }
    
            if status == errSecItemNotFound {
                status = withUnsafeMutablePointer(to: &result) {
                    SecItemAdd(queryLoad as CFDictionary, UnsafeMutablePointer($0))
                }
            }
    
            if status == noErr {
                if let resultDict = result as? [String: Any], let accessGroup = resultDict[kSecAttrAccessGroup as String] as? String {
                    let components = accessGroup.components(separatedBy: ".")
                    return components.first
                }else {
                    return nil
                }
            } else {
                print("Error getting bundleSeedID to Keychain")
                return nil
            }
        }
    

提交回复
热议问题