ここで私はそれを呼んでいます:
/**
* called when we are notified that a product has been purchased
*
* @param notification the notification object calling this method
*/
- (void)productPurchased:(NSNotification *)notification
{
// the notification object is purchased product identifier
NSString *productIdentifier = notification.object;
NSLog(@"Product purchased");
// reload appropriate cell with checkmark
[_products enumerateObjectsUsingBlock:^(SKProduct *product, NSUInteger idx, BOOL *stop)
{
NSLog(@"Block executing with product: %@", product.productIdentifier);
NSLog(@"Needs to match: %@", productIdentifier);
if ([product.productIdentifier isEqualToString:productIdentifier])
{
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:idx inSection:0]]
withRowAnimation:UITableViewRowAnimationFade];
NSLog(@"Reloading due to purchase");
*stop = YES;
}
}];
}
ただし、ブロックが呼び出されることはないため、テーブル ビュー セルが再ロードされることはありません。ログがコンソールに表示されないため、ブロックが実行されないことがわかります。ただし、ブレークポイントを配置することで、productPurchased: メソッドが確実に呼び出されていることを確認できました。
どんな助けでも大歓迎です。
ありがとうございました。
編集: 上記のコードを変更して、実行中により多くのログを記録できるようにしました。コンソールを見て収集できたものから、渡される通知オブジェクトはテーブル ビューそのものです。
<UITableView: 0x1eaffe00; frame = (0 0; 320 704); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x1e57dfe0>; layer = <CALayer: 0x1e57da50>; contentOffset: {0, 0}>
これは明らかにこの関数の呼び出しに問題があるため、さらに調査し、回答が得られ次第投稿します。
今のところ、この関数を呼び出す方法を含めます。
通知のための署名:
/**
* notifies the view controller that its view is about to be added to a view hierarchy
*
* @param animated whether it will be added in an animated fashion
*/
- (void)viewWillAppear:(BOOL)animated
{
// add ourselves as an observer to product purchases
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(productPurchased:) name:IAHelperProductPurchasedNotification object:nil];
}
通知の送信:
/**
* handles all the extra work not that a product has been purchased
*
* @param productIdentifier the purchased product's identifier
*/
- (void)provideContentForProductIdentifier:(NSString *)productIdentifier
{
// adds the product's id to our purchased product ids list
[_purchasedProductIdentifiers addObject:productIdentifier];
// stores this purchase in nsuserdefaults for long term use
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:productIdentifier];
// save the user defaults
[[NSUserDefaults standardUserDefaults] synchronize];
// send notification to tohers for awareness of this purchase
[[NSNotificationCenter defaultCenter] postNotificationName:IAHelperProductPurchasedNotification object:productIdentifier userInfo:nil];
}