在Android应用程序开发人员中,使用keystore
对其应用程序进行签名。他们可以使用keystore
之类的Android SDK来获取PackageManager
的摘要。即使在更新后,密钥库摘要对于相同的应用程序也是唯一的。
某些第三方开发人员在其第三个API中使用此摘要。例如,它在google的Maps API中使用。
现在我想知道在iOS中是否有这样的东西。这样我们就可以从iOS SDK中获取它,它对我的应用程序的所有版本都是唯一的吗?
答案 0 :(得分:0)
根据我的研究,我们可以使用Team ID
作为识别应用程序签名者的等效项。
团队ID是与iTunes Connect中的开发团队相关联的唯一标识符,并且与任何类型的Apple帐户(包括组织,个人或企业)一起发布的每个应用都具有这些唯一标识符。
我们应该注意到,我们必须从iOS SDK中读取它,而不是在plist中对其进行硬编码。我使用下面的代码:
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
NSDictionary *query = [NSDictionary dictionaryWithObjectsAndKeys:
(__bridge NSString *)kSecClassGenericPassword,
(__bridge NSString *)kSecClass,
string, kSecAttrAccount,
@"", kSecAttrService,
(id)kCFBooleanTrue, kSecReturnAttributes,
nil];
CFDictionaryRef result = nil;
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query,
(CFTypeRef *)&result
);
if (status == errSecItemNotFound)
status = SecItemAdd((__bridge CFDictionaryRef)query, (CFTypeRef *)&result);
if (status != errSecSuccess)
return nil;
NSString *accessGroup = [(__bridge NSDictionary *)result objectForKey:
(__bridge NSString *)kSecAttrAccessGroup
];
NSArray *components = [accessGroup componentsSeparatedByString:@"."];
NSString *bundleSeedID = [[components objectEnumerator] nextObject];
CFRelease(result);
最后,bundleSeedID
包含当前应用的teamID
。
答案 1 :(得分:-1)
您可以创建一个单独的plist配置文件来存储第三方API密钥,并使用[辅助函数]来检索它们。您可以添加custom runtime flag来选择调试密钥或释放密钥。您的帮助函数可能如下所示:
func valueForAPIKey(named keyname:String) -> String {
// Credit to the original source for this technique at
// http://blog.lazerwalker.com/blog/2014/05/14/handling-private-api-keys-in-open-source-ios-apps
let filePath = NSBundle.main().path(forResource: "ApiKeys", ofType: "plist")
let plist = NSDictionary(contentsOfFile:filePath!)
#if DEBUG
keyname = "\(keyname)-DEBUG"
#endif
let value = plist?.object(forKey: keyname) as! String
return value
}
来源:http://dev.iachieved.it/iachievedit/using-property-lists-for-api-keys-in-swift-applications/