1

私はスプライト キット ゲームを書いており、ゲーム内でアプリ内購入を行っています。で実装します

ファイル IAPHelper.m (IAPHelper.m は NSObject のサブクラス) でアプリを購入し、

購入が成功すると、nsnotification が投稿されます。コードは次のようになります。

- (void)completeTransaction:(SKPaymentTransaction *)transaction {
NSLog(@"completeTransaction...");

[self provideContentForProductIdentifier:transaction.payment.productIdentifier];

}

- (void)provideContentForProductIdentifier:(NSString *)productIdentifier {
NSLog(@"post a notification");

[[NSNotificationCenter defaultCenter] postNotificationName:IAPHelperProductPurchasedNotification object:productIdentifier     userInfo:nil];

 }

MyScene.m (MyScene.m は SKScene のサブクラスです) に、通知用のオブザーバーを追加します。

   -(id)initWithSize:(CGSize)size {    
     if (self = [super initWithSize:size]) {
    /* Setup your scene here */
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ok:) name:IAPHelperProductPurchasedNotification object:nil];

       }
    return self;

    }
  - (void)ok:(NSNotification *)notification {
  NSLog(@"Ok, I got it");

     }

そして、私がやろうとしているのは、IAPHelper.m が通知を投稿し、MyScene.m がそれを受信して​​応答することです。しかし、結果は、MyScene.m が通知を受け取っていないように見えるため、コードは

    - (void)ok:(NSNotification *)notification {
    NSLog(@"Ok, I got it");
     }

は呼び出されていません。しかし、ViewController.m (UIViewController のサブクラス) にオブザーバーを配置すると、機能します。私の質問は: skscene は任意のオブジェクトから通知を受け取ることができますか? また、可能であれば、それを実装する方法。

誰かがこの問題で私を助けることができれば、どうもありがとう.

4

0 に答える 0