Rod*_*nto 10 iphone objective-c storekit in-app-purchase ios
"要检查购买是否已取消,请在收据中查找取消日期字段.如果该字段中包含日期,则无论订阅的到期日期如何,购买都已取消 - 将取消的收据视为与取消收据相同从来没有购买过."
但收据未显示"取消日期"字段:
"expires_date" = "2015-04-29 16:46:26 Etc/GMT";
"expires_date_ms" = 1430325986000;
"expires_date_pst" = "2015-04-29 09:46:26 America/Los_Angeles";
"is_trial_period" = false;
"original_purchase_date" = "2015-04-29 16:27:40 Etc/GMT";
"original_purchase_date_ms" = 1430324860000;
"original_purchase_date_pst" = "2015-04-29 09:27:40 America/Los_Angeles";
"original_transaction_id" = 1000000153387111;
"product_id" = ...;
"purchase_date" = "2015-04-29 16:31:26 Etc/GMT";
"purchase_date_ms" = 1430325086000;
"purchase_date_pst" = "2015-04-29 09:31:26 America/Los_Angeles";
quantity = 1;
"transaction_id" = ...;
"web_order_line_item_id" = ...;
Run Code Online (Sandbox Code Playgroud)
Apple表示不会管理用户的订阅,而是转而使用iTunes:
"您的应用程序可以打开以下URL,而不是需要编写自己的订阅管理UI代码:https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/manageSubscriptions 打开此URL会启动iTunes或iTunes Store,然后显示"管理订阅"页面."
但是这不可能使用Sandbox帐户进行测试(需要信用卡).我真的需要测试取消订阅.
这是我用来获取收据的代码:
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:receiptURL];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *receipt = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (receipt) {
// Create the JSON object that describes the request
NSError *error;
NSDictionary *requestContents = @{
@"receipt-data": [receipt base64EncodedStringWithOptions:0],
@"password": @"...",
};
NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents
options:0
error:&error];
if (!requestData) {
NSLog(@"Unable to serialise json data. Possible user/password mistake. Error: %@", error);
}
// Create a POST request with the receipt data.
NSURL *storeURL = [NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"];
NSMutableURLRequest *storeRequest = [NSMutableURLRequest requestWithURL:storeURL];
[storeRequest setHTTPMethod:@"POST"];
[storeRequest setHTTPBody:requestData];
// Make a connection to the iTunes Store on a background queue.
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:storeRequest queue:queue
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (connectionError) {
NSLog(@"Connection error: %@", connectionError);
} else {
NSError *error;
NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
NSArray *receiptInfo = jsonResponse[@"latest_receipt_info"];
NSInteger total = receiptInfo.count;
NSDictionary *receiptDict = receiptInfo[total-1];
NSLog(@"Json: %@", receiptInfo);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1821 次 |
| 最近记录: |