不跳轉(zhuǎn)AppStore. 原來(lái)是IOS6.0就有的新的特性毕贼,這和程序自動(dòng)更新跳轉(zhuǎn)應(yīng)用商店是一個(gè)作用温赔。不同的是,這個(gè)可以在應(yīng)用內(nèi)部直接打開(kāi)鬼癣,不需要挑轉(zhuǎn)到應(yīng)用商店陶贼,當(dāng)完成操作以后,就可以直接返回到本應(yīng)用當(dāng)前操作的界面待秃。用法如下:
SKStoreProductViewController類(lèi)是UIViewController的子類(lèi), 如果你對(duì)view controller比較熟悉的話(huà)拜秧,那SKStoreProductViewController使用起來(lái)也非常簡(jiǎn)單了。當(dāng)你希望向用戶(hù)展示App Store中產(chǎn)品時(shí)锥余,你需要:
1.實(shí)例化一個(gè)SKStoreProductViewController類(lèi)?
2.設(shè)置它的delegate?
3.把sotre product視圖控制器顯示給消費(fèi)者
剩下的就交給操作系統(tǒng)來(lái)處理了腹纳。需要記住一點(diǎn)的是SKStoreProductViewController只能以模態(tài)的方式顯示。SKStoreProductViewControllerDelegate協(xié)議定義了一個(gè)單獨(dú)的方法—productViewControllerDidFinish:驱犹,當(dāng)消費(fèi)者離開(kāi)App Store時(shí)會(huì)調(diào)用這個(gè)方法—一般是通過(guò)點(diǎn)擊左上角畫(huà)面中的取消按鈕嘲恍。通過(guò)給代理發(fā)送productViewControllerDidFinish:消息,操作系統(tǒng)就會(huì)把控制權(quán)返回到你的程序雄驹。當(dāng)然你不能忘了 只支持IOS6.0及其以上~~
代碼如下:
//
//? ViewController.m
//? 消費(fèi)者demo
//
//? Created by mac on 2018/8/9.
//? Copyright ? 2018年 com.zkr. All rights reserved.
//
#import "ViewController.h"
#import
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
? ? [super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
? ? [super didReceiveMemoryWarning];
? ? // Dispose of any resources that can be recreated.
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event{ ? ?SKStoreProductViewController *skstore = [[SKStoreProductViewController alloc] init];
skstore.delegate=self;
[self presentViewController:skstore animated:YES completion:nil];
//最后加載應(yīng)用數(shù)據(jù)(一定要記住這個(gè)數(shù)據(jù)要在視圖出現(xiàn)以后去加載)
?[skstore loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:@(自己程序的ID)} completionBlock:^(BOOL result, NSError * _Nullable error) {
if(error) {
? ? ? ? ? ? //handle the error
?}
? ? }];
? ? //present
}
//注意一定要有代理方法佃牛,不然,當(dāng)你返回
- (void)productViewControllerDidFinish:(SKStoreProductViewController*)viewController {
?? ?[viewController dismissViewControllerAnimated:YES
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?completion:nil];
}
如果對(duì)你有用医舆,記得點(diǎn)贊和關(guān)注胺馈!