2

In Android application developers use a keystore to sign their applications. They can fetch the digest of the keystore by using some Android SDK's like PackageManager. The keystore digest is unique for same apps even after update.

Some third developers use this digest in their third APIs. For example it is using in Maps API of google.

Now I am wondered is there something like this in iOS. So that we can fetch it from iOS SDK and it be unique for all versions of my application?

Husein Behboudi Rad
  • 5,434
  • 11
  • 57
  • 115

2 Answers2

0

Base on my researches we can use Team ID as an equivalent for identifying the signer of an app.

Team ID is a unique identifier associated to a development team in iTunes Connect and each app that is publishing with any kind of Apple accounts (including organization, individual or enterprise ) has these unique identifier.

Just we should notice that we have to read this from the iOS SDK not hardcoding it in the plist. I use below code:

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);

Finally the bundleSeedID contains the teamID of current app.

Husein Behboudi Rad
  • 5,434
  • 11
  • 57
  • 115
-1

You could create a separate plist configuration file to store your 3rd party API keys and use a [helper function] to retrieve them. You can add a custom runtime flag to choose a debug key or release key. Your helper function could look something like this:

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
}

Source: http://dev.iachieved.it/iachievedit/using-property-lists-for-api-keys-in-swift-applications/

Community
  • 1
  • 1
  • I need something that deepends on the sign of app. – Husein Behboudi Rad Nov 08 '16 at 09:57
  • You could use [custom Swift flags](http://stackoverflow.com/a/24112024/7106197) with different build configurations to get the correct key on runtime. You could have one key named GOOGLE-KEY and another GOOGLE-KEY-DEBUG and use it like this: – Kevin Hoffman Nov 08 '16 at 16:23
  • 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!) let value = plist?.object(forKey: keyname) as! String return value } – Kevin Hoffman Nov 08 '16 at 16:24
  • 1
    Hottman , plist is not depent on sign. if you read the question I need something that if we change the sign then the values changes automatically. plist is something like hardcoding string in a file. I need somthing that if a hacker reverse engineered the file and then resign it with another account the value change automatically by apple. – Husein Behboudi Rad Nov 09 '16 at 05:01