调用StoreService函数登陆iTunesStore

2017-11-12  本文已影响0人  iosjoker

typedef void(^CallbackBlock)(NSString* resp);

-(void) signIn: (NSString*) username password:(NSString*)password callback: (CallbackBlock) callback {

    NSLog(@"check Account: %@, %@", username, password);

SSAccountStore* accountStore =  [SSAccountStore defaultStore];

NSArray* accountTable = [accountStore accounts];

NSLog(@"account cache count %d",(int)accountTable.count);

for (SSAccount* account in accountTable){

NSLog(@"account name %@\n", [account accountName]);

}

[accountStore signOutAllAccounts];

SSAuthenticateRequest *req = [SSAuthenticateRequest alloc];

NSLog(@"allocate request ok\n");

SSMutableAuthenticationContext *context = [SSMutableAuthenticationContext  contextForSignIn];

NSLog(@"get context for signin ok");

SSAccount * account = [SSAccount alloc];

[account setAccountName: username];

[context initWithAccount: account];

[context setInitialPassword: password];

NSLog(@"set account ok");

NSLog(@"%@", req.delegate);

[req initWithAuthenticationContext:context];

NSLog(@"init authentication ok");

typedef void(^Block)(SSAuthenticateResponse* response1);

Block block = ^(SSAuthenticateResponse* authResponse){// 参数个数可能有问题。 还好arm64 是寄存器传参。

NSLog(@"login response callback here %@", authResponse);

NSLog(@"callback authResponseType %d", [authResponse authenticateResponseType]);

SSAccount * account = [authResponse authenticatedAccount];

NSLog(@"callback authResponse accountName %@ isActive %d isAuthed %d",

[account accountName], [account isActive], [account isAuthenticated]);

NSLog(@"callback authResponse firstName %@ lastName %@ ITunesPassSerialNumber %@ creditsString[卡上多少钱] %@ ",

[account firstName], [account lastName], [account ITunesPassSerialNumber], [account creditsString]);

NSLog(@"callback authResponse isNewCustomer %d secureToken %@ uniqueIdentifier[appleID 编号] %@",

[account isNewCustomer], [account secureToken], [account uniqueIdentifier]);

//

if ([authResponse authenticateResponseType] != 0) {

if (callback != nil)

callback(@"ok");

} else {

if (callback != nil)

callback(@"fail");

}

};

[req startWithAuthenticateResponseBlock:block];

NSLog(@"start authentication finish... block call back I dont known.");

}

排版太难看,直接贴图

上一篇 下一篇

猜你喜欢

热点阅读