IOS6.0 应用内直接下载程序 不需跳转AppStore
閑來沒事看了篇文章 應(yīng)用內(nèi)創(chuàng)建應(yīng)用商店環(huán)境,不跳轉(zhuǎn)AppStore. 先武斷的想一句:放屁。然后好奇的進去看看,原來是IOS6.0的新特性,頓感慚愧。研究下
?
SKStoreProductViewController類是UIViewController的子類, 如果你對view controller比較熟悉的話,那SKStoreProductViewController使用起來也非常簡單了。當(dāng)你希望向用戶展示App Store中產(chǎn)品時,你需要:
1.實例化一個SKStoreProductViewController類
2.設(shè)置它的delegate
3.把sotre product視圖控制器顯示給消費者
?
剩下的就交給操作系統(tǒng)來處理了。需要記住一點的是SKStoreProductViewController只能以模態(tài)的方式顯示。SKStoreProductViewControllerDelegate協(xié)議定義了一個單獨的方法—productViewControllerDidFinish:,當(dāng)消費者離開App Store時會調(diào)用這個方法—一般是通過點擊左上角畫面中的取消按鈕。通過給代理發(fā)送productViewControllerDidFinish:消息,操作系統(tǒng)就會把控制權(quán)返回到你的程序。當(dāng)然你不能忘了 只支持IOS6.0及其以上~~
?
步驟:
1.添加 storeKit.framework
2.頭文件里 加上 ?
#import <StoreKit/StoreKit.h>
@interface ViewController : UIViewController<SKStoreProductViewControllerDelegate>
3.直接在m中實現(xiàn)
- (IBAction)doAction:(UIButton *)sender {
? ? ? [self showAppInApp:@"xxxxxx"];//此處xxxxx需要替換為需要的appID
}
- (void)showAppInApp:(NSString *)_appId {
? Class isAllow = NSClassFromString(@"SKStoreProductViewController");
? if (isAllow != nil) {
? ? SKStoreProductViewController *sKStoreProductViewController = [[SKStoreProductViewController alloc] init];
? ? sKStoreProductViewController.delegate = self;
? ? [sKStoreProductViewController loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier: _appId}
? ? ? ? ? ? ? ? ? ? ? completionBlock:^(BOOL result, NSError *error) {
? ? ? ? ? ? ? ? ? ? ? ? if (result) {
? ? ? ? ? ? ? ? ? ? ? ? ? [self presentViewController:_SKSVC
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?animated:YES
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?completion:nil];
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? else{
? ? ? ? ? ? ? ? ? ? ? ? ? NSLog(@"%@",error);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? }];
? }
? else{
? ? //低于iOS6沒有這個類
? ? NSString *string = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/us/app/id%@?mt=8",_appId];
? ? [[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]];
? }
}
#pragma mark - SKStoreProductViewControllerDelegate?
//對視圖消失的處理
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
? [viewController dismissViewControllerAnimated:YES
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?completion:nil];
}
?
轉(zhuǎn)載于:https://www.cnblogs.com/superhappy/archive/2013/05/09/3069210.html
總結(jié)
以上是生活随笔為你收集整理的IOS6.0 应用内直接下载程序 不需跳转AppStore的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。