In App Purchase iOS access AppleId

不羁岁月 提交于 2019-12-12 08:59:57

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/14023954/in-app-purchase-ios-access-appleid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!