Iphone 除非重新启动应用程序,否则不会在IAP后删除广告?
在我的应用程序中,有一个代码,如果按下按钮,用户可以升级应用程序并删除广告,它会调用MKStoreKit,一旦用户购买了升级,广告将保留在应用程序中,直到应用程序重新启动 我想解决这个问题,所以广告会立即删除,但我该怎么做呢 下面是一些代码Iphone 除非重新启动应用程序,否则不会在IAP后删除广告?,iphone,ios,xcode,storekit,Iphone,Ios,Xcode,Storekit,在我的应用程序中,有一个代码,如果按下按钮,用户可以升级应用程序并删除广告,它会调用MKStoreKit,一旦用户购买了升级,广告将保留在应用程序中,直到应用程序重新启动 我想解决这个问题,所以广告会立即删除,但我该怎么做呢 下面是一些代码 -(IBAction)removeAds:(id)sender { if (![MKStoreManager isFeaturePurchased:@"com.davidsapps.puzzler.removeads"]) { //
-(IBAction)removeAds:(id)sender
{
if (![MKStoreManager isFeaturePurchased:@"com.davidsapps.puzzler.removeads"]) { //
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Upgrade App" message:@"To upgrade and remove all advertisements from this app Please click OK to purchase the upgrade!" delegate:self cancelButtonTitle:@"No Thanks" otherButtonTitles:@"Yes Please",nil];
[alert show];
[alert release];
}
}
它链接到的警报
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0){
//cancel button clicked. Do something here or nothing here
}
else{
//other button indexes clicked
[[MKStoreManager sharedManager] buyFeature:@- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0){
//cancel button clicked. Do something here or nothing here
}
else{
//other button indexes clicked
[[MKStoreManager sharedManager] buyFeature:@"com.idevver.mybatterypal.upgrade"];
}
}
}
使用MKStoreKit
我能做些什么,让它在用户不必重新启动应用程序的情况下删除广告
谢谢
克里斯
编辑-广告是Admob中介,在ViewDidLoad中使用此代码
- (void)viewDidLoad {
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
bannerView_.adUnitID = MY_BANNER_UNIT_ID;
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
CGFloat screenXPos = (screenWidth /2);
CGFloat screenYPos = screenHeight - 90;
[bannerView_ setCenter:CGPointMake(screenXPos, screenYPos)];
bannerView_.rootViewController = self;
bannerView_.adUnitID = MY_BANNER_UNIT_ID;
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
这是实际调用广告横幅的代码,它位于viewDidLoad后面的if/else语句中
if (![MKStoreManager isFeaturePurchased:@"com.davidsapps.puzzler.removeads"]) { //
[bannerView_ loadRequest:[GADRequest request]];
}
因此,我想当购买该功能时,我需要在MKStoreManager.m文件中添加一些内容,比如说,删除上面的bannerView_uuu代码
这样行吗
编辑应用程序内代码的2-Full.m文件(感谢MugunthKumar提供的精彩工具包)
//
//MKStoreManager.m
//MKStoreKit
//
//由Mugunth Kumar于2010年11月17日创作。
//版权所有2010 Steinlogic。版权所有。
//Mugunth Kumar使用Singleton XCode模板创建的文件(http://mugunthkumar.com
//除了删除上面的行/URL之外,授予对该文件执行任何商业/非商业操作的权限
//阅读我在http://mk.sg/1m 关于如何使用此代码
/作为使用此代码的一个旁注,您可以考虑给予我一些信任。
//1)从应用程序的网站链接我的网站
//2)或在应用程序的“积分”页面中为我积分
//3)或一条提到@mugunthkumar的推特
//4)贝宝捐赠给mugunth。kumar@gmail.com
//
//关于再分配的注记
//虽然我可以修改源代码,
//如果您在编辑后重新发布,请保留上述版权声明
#导入“MKStoreManager.h”
#导入“gadbanerview.h”
#导入“AppDelegate.h”
@接口MKStoreManager(私有方法)
-(无效)请求产品数据;
-(BOOL)canCurrentDeviceUseFeature:(NSString*)特性ID;
-(BOOL)验证接收:(NSData*)接收数据;
-(void)启用此会话的内容:(NSString*)productIdentifier;
@结束
@实现管理器
@综合purchasableObjects=\u purchasableObjects;
@综合storeObserver=\u storeObserver;
静态NSString*ownServer=nil;
静态弱id委托;
静态MKStoreManager*_sharedStoreManager;
-(无效)解除锁定{
[_purchasableObjects发布];
[_storeObserver发布];
[_sharedStoreManager发布];
[super dealoc];
}
#pragma标记代表
+(id)代表{
返回代表;
}
+(void)setDelegate:(id)newDelegate{
_delegate=newDelegate;
}
#pragma-mark单例方法
+(MKStoreManager*)共享管理器
{
@同步(自){
如果(_sharedStoreManager==nil){
#if TARGET_IPHONE_模拟器
NSLog(@“您在模拟器中运行,MKStoreKit仅在设备上运行”);
#否则
_sharedStoreManager=[[self alloc]init];
_sharedStoreManager.PurchableObjects=[[NSMutableArray alloc]init];
[_SharedStoreManagerRequestProductData];
_sharedStoreManager.storeObserver=[[MKStoreObserver alloc]init];
[[SKPaymentQueue defaultQueue]addTransactionObserver:_sharedStoreManager.storeObserver];
#恩迪夫
}
}
return(u sharedStoreManager);
}
+(id)allocWithZone:(NSZone*)区域
{
@同步(自){
如果(_sharedStoreManager==nil){
_sharedStoreManager=[super allocWithZone:zone];
return _sharedStoreManager;//首次分配时的分配和返回
}
}
return nil;//在随后的分配尝试中返回nil
}
-(id)copyWithZone:(NSZone*)区
{
回归自我;
}
-(id)保留
{
回归自我;
}
-(未签名)重新计数
{
return UINT_MAX;//表示无法释放的对象
}
-(无效)释放
{
//无所事事
}
-(id)自动释放
{
回归自我;
}
#pragma标记内部MKStoreKit函数
-(无效)恢复以前的交易
{
[[SKPaymentQueue defaultQueue]恢复完成的事务];
}
-(void)请求产品数据
{
SKProductsRequest*请求=[[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet setWithObjects:
kFeatureAId,
kConsumableFeatureBId,
kConsumableBaseFeatureId,
无]];
request.delegate=self;
[请求启动];
}
-(无效)产品请求:(SKProductsRequest*)请求DID接收方响应:(SKProductsResponse*)响应
{
[self.purchableObjects addObjectsFromArray:response.products];
#ifndef NDEBUG
对于(int i=0;i当购买完成时,由您删除广告。执行类似操作
[bannerView removeFromSuperview];
您所要做的就是在购买完成后隐藏广告。您可能需要添加一些关于如何显示广告的代码。您是否使用IAD、AdMob等?嗨,乔-我更新了原始问题,以显示我使用的一些广告代码:)嗨,广告代码,正在使用Admob中介,我只是加载GAD横幅视图,我已经将其添加到我的原始问题中,添加到视图中的代码加载我已经更新了我的问题,希望这会有所帮助:)嗨,杰克,我会把它放在哪里,就像我把它放在removeAds iAction上一样,然后发生的一切,是当用户按下该按钮,即使他们解除警报,横幅也会消失,而他们不需要购买?问候,克里斯。哦,我理解。你知道如何检查应用内购买何时完成吗?不幸的是:(我想它可能在MKStoreManager.m代码中?其中有很多东西。)
[bannerView removeFromSuperview];