我需要您的建議,使用「在應用程序購買」刪除iAd。 我有「In App Purchase」的工作代碼。但我不知道如何實現它(IOS)SpriteKit遊戲。當我在View Controller中實現它時工作得很好,但我需要它在MyScene.m中工作,所以當我點擊「-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
」方法中的「購買」警報窗口時,會彈出並讓玩家購買它In App購買集成SpriteKit
This code is working in Storyboard and has IBbutton but it is not seen in SKScene.
I am beginner developer and know how SKScene and MyScene but thats now enough.
If you want to look at code let me know thanks
Here is ny Code:
in View Controller.h I declare
@interface ViewController : UIViewController <ADBannerViewDelegate>
{
IBOutlet ADBannerView *iadBanner;
//
}
@property (nonatomic,strong) NSArray*products;
@property(nonatomic,strong)NSUserDefaults*defaults;
@end
In ViewController.m
#import "MyNewlyCreatedScene.h"
#import "ViewController.h"
#import <StoreKit/StoreKit.h>
@interface ViewController()
@end
@implementation ViewController
@synthesize /*idBanner*/ products,defaults;
- (void)viewDidLoad
{
[super viewDidLoad];
[[SKPaymentQueue defaultQueue]addTransactionObserver:(id)self];
defaults =[NSUserDefaults standardUserDefaults];
BOOL isPro=[defaults boolForKey:@"isPro"];
if (!isPro) {
//user code here
[self fetchProducts];
} else {
iadBanner.alpha=0.0;
}
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
defaults =[NSUserDefaults standardUserDefaults];
BOOL isPro=[defaults boolForKey:@"isPro"];
if (!isPro) {
//user code here
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
else
{
iadBanner.alpha=0.0;
}
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];
}
-(void)fetchProducts{
SKProductsRequest*request = [[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet
setWithArray:@[@"testingAppPurchaseID "]]];
request.delegate = (id)self;
[request start];
}
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
products = response.products;
NSLog(@"Product was purchased");
}
-(void)request:(SKRequest*)request didFailWithError:(NSError *)error{
NSLog(@"%@",error);
}
-(void)buy:(SKProduct*)product{
SKPayment *payment = [SKPayment paymentWithProduct:product];
[[SKPaymentQueue defaultQueue]addPayment:payment];
}
-(IBAction)removeAdvertisment:(id)sender
{
SKProduct *prod = [products objectAtIndex:0];
[self buy:prod];
}
-(void)paymentQueue:(SKPaymentQueue*)queue updatedTransactions:(NSArray *)transactions{
for (SKPaymentTransaction *tx in transactions) {
switch (tx.transactionState) {
case SKPaymentTransactionStatePurchased:
[[SKPaymentQueue defaultQueue]finishTransaction:tx];
//_____________________
iadBanner.alpha=0.0;
//______________________
[defaults setBool:YES forKey:@"isPro"];
break;
case SKPaymentTransactionStateFailed:
[[SKPaymentQueue defaultQueue]finishTransaction:tx];
NSLog(@"Error:%@",tx.error);
break;
case SKPaymentTransactionStateRestored:
[[SKPaymentQueue defaultQueue]finishTransaction:tx];
break;
default:
break;
}
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];``
}
@end
In Storyboard I add iAdbannerView and a button and connect button to action, and set iAdbannerView to delegate
Give me some hints how to solve this problem.
我確定有很多開發者爲什麼在應用商店中有遊戲,這意味着你們中的一些人在MyScene中實現了IN App Purchase,所以請幫助。
「如果你想看代碼,讓我知道」......不,我們**有**看代碼。如果你的代碼有問題,你應該發佈你的代碼,我們還有什麼建議改進和指出問題的? – LearnCocos2D 2014-11-01 10:35:05