{"id":136,"date":"2010-02-04T01:22:44","date_gmt":"2010-02-03T16:22:44","guid":{"rendered":"http:\/\/yshobby.asia\/jp\/?p=136"},"modified":"2013-10-31T13:36:47","modified_gmt":"2013-10-31T04:36:47","slug":"in-app-purchase%e3%81%ae%e3%82%b5%e3%83%b3%e3%83%97%e3%83%ab%e3%82%82%e3%81%a9%e3%81%8d","status":"publish","type":"post","link":"https:\/\/enjoyahobby.com\/jp\/archives\/136","title":{"rendered":"In App Purchase\u306e\u30b5\u30f3\u30d7\u30eb\u3082\u3069\u304d"},"content":{"rendered":"<p>2013.10.31\u8ffd\u8a18<br \/>\n\u53e4\u3044\u306e\u3067\u53c2\u8003\u306b\u306f\u306a\u3089\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u300ciPhone&#038;Android\u30a2\u30d7\u30ea\u5185\u8ab2\u91d1\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u5b8c\u5168\u30ac\u30a4\u30c9\u300d\u306a\u3069\u53c2\u8003\u306b\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u30a8\u30e9\u30fc\u30c1\u30a7\u30c3\u30af\u3082\u4f55\u3082\u7121\u3044\u7701\u7565\u3057\u307e\u304f\u308a\u30bd\u30d5\u30c8\u306e\u6982\u7565\u3067\u3059\u3002\u679d\u8449\u306f\u81ea\u5206\u3067\u3061\u3083\u3093\u3068\u4ed8\u3051\u52a0\u3048\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\uff03\u30b3\u30d4\u30da\u3057\u305f\u6642\u306b\u6f0f\u308c\u304c\u3042\u3063\u305f\u307f\u305f\u3044\u306a\u306e\u3067\u4fee\u6b63\u3057\u307e\u3057\u305f\u30022010.2.4<\/p>\n<p>\u307e\u305a\u306fStoreKitObserver<\/p>\n<pre>MyStoreKitObserver.h\r\n#import &lt;Foundation\/Foundation.h&gt;\r\n#import &lt;StoreKit\/StoreKit.h&gt;\r\n@interface MyStoreKitObserver : NSObject &lt;SKPaymentTransactionObserver&gt; {\r\n}\r\n@end\r\n\r\nMyStoreKitObserver.m\r\n#import \"MyStoreKitObserver.h\"\r\n@implementation MyStoreKitObserver\r\n-(id)init {\r\n\tif (self = [super init]) {\r\n\t}\r\n\treturn self;\r\n}\r\n- (void)paymentQueue:(SKPaymentQueue *)queue removedTransactions:(NSArray *)transactions {\r\n}\r\n- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {\r\n\tfor (SKPaymentTransaction *transaction in transactions) {\r\n\t\tswitch (transaction.transactionState) {\r\n\t\tcase SKPaymentTransactionStatePurchasing:\r\n\t\t\tbreak;\r\n\t\tcase SKPaymentTransactionStatePurchased:\r\n\t\tcase SKPaymentTransactionStateFailed:\r\n\t\tcase SKPaymentTransactionStateRestored:\r\n\t\t\t[[SKPaymentQueue defaultQueue] finishTransaction:transaction];\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n}\r\n@end<\/pre>\n<p>\u3042\u3068\u306f\u9069\u5f53\u306b\u30dc\u30bf\u30f3\u3092\u7528\u610f\u3057\u3066<\/p>\n<pre>TestStoreViewController.h\r\n#import &lt;UIKit\/UIKit.h&gt;\r\n#import &lt;StoreKit\/StoreKit.h&gt;\r\n@class MyStoreKitObserver;\r\n@interface TestStoreViewController : UIViewController &lt;SKProductsRequestDelegate&gt; {\r\n\tMyStoreKitObserver\t*mySKObserver;\r\n}\r\n-(IBAction)test1Action:(id)sender;\r\n@end\r\n\r\nTestStoreViewController.m\r\n#import \"TestStoreViewController.h\"\r\n#import \"MyStoreKitObserver.h\"\r\n@implementation TestStoreViewController\r\n-(IBAction)test1Action:(id)sender {\r\n\tSKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet\r\nsetWithObject:@\"item1\"]];\t\/\/ \u81ea\u5206\u3067\u3064\u3051\u305f\u30a2\u30a4\u30c6\u30e0ID\r\n\trequest.delegate = self;\r\n\t[request start];\r\n}\r\n- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {\r\n\tNSArray *myProduct = response.products;\r\n\tif([myProduct count] &gt; 0) {\t\/\/1\u30a2\u30a4\u30c6\u30e0\u3057\u304b\u51e6\u7406\u3057\u3066\u307e\u305b\u3093\r\n\t\tSKProduct *product = [myProduct objectAtIndex:0];\r\n\t\tSKPayment *payment = [SKPayment paymentWithProductIdentifier:product.productIdentifier];\r\n\t\t[[SKPaymentQueue defaultQueue] addPayment:payment];\r\n\t}\r\n}\r\n- (void)viewDidLoad {\r\n\t[super viewDidLoad];\r\n\tmySKObserver = [[MyStoreKitObserver alloc] init];\r\n\t[[SKPaymentQueue defaultQueue] addTransactionObserver: mySKObserver];\r\n\tUIApplication *app = [UIApplication sharedApplication];\r\n\t[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:app];\r\n\t[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];\r\n}\r\n-(void)_applicationWillTerminate:(NSNotification*)notification\r\n{\r\n\t[[SKPaymentQueue defaultQueue] removeTransactionObserver: mySKObserver];\r\n\t[mySKObserver release];\r\n}<\/pre>\n<p>\u4e00\u5fdc\u52d5\u4f5c\u78ba\u8a8d\u306f\u3057\u307e\u3057\u305f\u304c\u7121\u4fdd\u8a3c\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2013.10.31\u8ffd\u8a18 \u53e4\u3044\u306e\u3067\u53c2\u8003\u306b\u306f\u306a\u3089\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u3002 \u300ciPhone&#038;Android\u30a2\u30d7\u30ea\u5185\u8ab2\u91d1\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u5b8c\u5168\u30ac\u30a4\u30c9\u300d\u306a\u3069\u53c2\u8003\u306b\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002 \u30a8\u30e9\u30fc\u30c1\u30a7\u30c3\u30af\u3082\u4f55\u3082\u7121\u3044\u7701\u7565\u3057\u307e\u304f\u308a\u30bd\u30d5\u30c8\u306e\u6982\u7565 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3],"tags":[],"class_list":["post-136","post","type-post","status-publish","format-standard","hentry","category-iphone-dev","category-3"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/enjoyahobby.com\/jp\/wp-json\/wp\/v2\/posts\/136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enjoyahobby.com\/jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enjoyahobby.com\/jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enjoyahobby.com\/jp\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/enjoyahobby.com\/jp\/wp-json\/wp\/v2\/comments?post=136"}],"version-history":[{"count":9,"href":"https:\/\/enjoyahobby.com\/jp\/wp-json\/wp\/v2\/posts\/136\/revisions"}],"predecessor-version":[{"id":575,"href":"https:\/\/enjoyahobby.com\/jp\/wp-json\/wp\/v2\/posts\/136\/revisions\/575"}],"wp:attachment":[{"href":"https:\/\/enjoyahobby.com\/jp\/wp-json\/wp\/v2\/media?parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoyahobby.com\/jp\/wp-json\/wp\/v2\/categories?post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoyahobby.com\/jp\/wp-json\/wp\/v2\/tags?post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}