Question

Is there a way to access apple id that is enter by user in authentication dialog while doing in-app purchase (email or their internal id) after purchase is done?

Était-ce utile?

La solution

In an official application, there's no way of accessing it, since it would impose great security exploits (for example, one could easily send spam to the specified e-mail address).

However, if you're using a jailbroken device, you can get the necessary information from the keychain. The appropriate keychain items have their svce key set to com.apple.itunesstored.token, and the e-mail address corresponds to the acct key. The security class of these entries is kSecClassGenericPassword. Just make sure you codesign your app using the appropriate entitlements (you'll need "keychain-access-groups" = "*").

An actual example for retrieving the needed information would be something like this:

#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
#import <Security/Security.h>

int main()
{
    NSMutableDictionary *query = [NSMutableDictionary dictionary];
    [query setObject:kSecClassGenericPassword forKey:kSecClass];
    [query setObject:kSecMatchLimitAll forKey:kSecMatchLimit];
    [query setObject:kCFBooleanTrue forKey:kSecReturnAttributes];
    [query setObject:kCFBooleanTrue forKey:kSecReturnRef];
    [query setObject:kCFBooleanTrue forKey:kSecReturnData];
    NSArray *items = nil;
    SecItemCopyMatching(query, &items);

    for (NSDictionary *item in items) {
        if ([[item objectForKey:@"svce"] isEqualToString:@"com.apple.itunesstored.token"]) {
            NSLog(@"Found iTunes Store account: %@", [item objectForKey:@"acct"]);
        }
    }

    return 0;
}

The entitlements.xml file (codesign using ldid -Sentitlemens.xml binary):

<plist>
<dict>
    <key>keychain-access-groups</key>
    <array>
        <string>*</string>
    </array>
</dict>
</plist>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top