-(BOOL) Putstringtoitunes: (nsdata*) iapdata{//The transactionreceipt of the user's successful purchase
Base64encodedstring
NSSTRING*ENCODINGSTR = [Iapdata base64encoding];
NSString *[email protected] "https://sandbox.itunes.apple.com/verifyReceipt";
Https://buy.itunes.apple.com/verifyReceipt
Nsmutableurlrequest *request = [[Nsmutableurlrequest alloc] init];//autorelease];
[Request Seturl:[nsurl Urlwithstring:url];
[Request sethttpmethod:@ "POST"];
Set ContentType
[Request addvalue:@ "Application/json" forhttpheaderfield:@ "Content-type"];
Set Content-length
[Request setvalue:[nsstring stringwithformat:@ "%d", [encodingstr length]] forhttpheaderfield:@ "content-length"];
nsdictionary* BODY = [Nsdictionary dictionarywithobjectsandkeys:encodingstr, @ "Receipt-data", nil];
Sbjsonwriter *writer = [Sbjsonwriter new];
[Request Sethttpbody:[[body Jsonrepresentation] datausingencoding:nsasciistringencoding AllowLossyConversion:YES] ;
[Request Sethttpbody:[[writer Stringwithobject:body] Datausingencoding:nsasciistringencoding Allowlossyconversion:yes]];
Nshttpurlresponse *urlresponse=nil;
Nserror *errorr=nil;
NSData *receiveddata = [Nsurlconnection sendsynchronousrequest:request
Returningresponse:&urlresponse
error:&errorr];
Analytical
NSString *results=[[nsstring alloc]initwithbytes:[receiveddata bytes] length:[receiveddata length] Encoding: Nsutf8stringencoding];
Debuglog (@ "-results-%@", results);
Nsdictionary*dic = [Results jsonvalue];
if ([[DiC objectforkey:@ "status"] intvalue]==0) {//note, [email protected] "0" is the verification receipt successful
return true;
}
return false;
}
This validation is not recommended for clients and should be done by the server.
But my side of the situation is the service-side verification is always unsuccessful, in order to prove that I passed his credentials no problem, find this method, prove that I pass the voucher no problem.
IAP verification.