IOS 應(yīng)用內(nèi)直接下載程序 不需跳轉(zhuǎn)AppStore

不跳轉(zhuǎn)AppStore. 原來是IOS6.0就有的新的特性,這和程序自動(dòng)更新跳轉(zhuǎn)應(yīng)用商店是一個(gè)作用。不同的是,這個(gè)可以在應(yīng)用內(nèi)部直接打開,不需要挑轉(zhuǎn)到應(yīng)用商店,當(dāng)完成操作以后,就可以直接返回到本應(yīng)用當(dāng)前操作的界面。用法如下:

SKStoreProductViewController類是UIViewController的子類, 如果你對(duì)view controller比較熟悉的話,那SKStoreProductViewController使用起來也非常簡(jiǎn)單了。當(dāng)你希望向用戶展示App Store中產(chǎn)品時(shí),你需要:

1.實(shí)例化一個(gè)SKStoreProductViewController類?

2.設(shè)置它的delegate?

3.把sotre product視圖控制器顯示給消費(fèi)者

剩下的就交給操作系統(tǒng)來處理了。需要記住一點(diǎn)的是SKStoreProductViewController只能以模態(tài)的方式顯示。SKStoreProductViewControllerDelegate協(xié)議定義了一個(gè)單獨(dú)的方法—productViewControllerDidFinish:,當(dāng)消費(fèi)者離開App Store時(shí)會(huì)調(diào)用這個(gè)方法—一般是通過點(diǎn)擊左上角畫面中的取消按鈕。通過給代理發(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)注??!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容