打開AppStore的方式

一.通過SKStoreProductViewController (modal 樣式)實現(xiàn) 在當前應用內(nèi)打開 App Store
1.遵守 <SKStoreProductViewControllerDelegate>
2.實現(xiàn) <SKStoreProductViewControllerDelegate>

#pragma mark - Download HLM in SKStoreProductViewController
- (void)openAppFromAppStore:(NSString *)appid {
    if (nil == appid || appid.length <= 0) {
        return;
    }
    
    //loading
    [SVProgressHUD show];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
    
//    // 改變導航欄的文字和圖片顏色
//    [[UINavigationBar appearance] setTintColor:[UIColor greenColor]];
//    // 紅色導航欄
//    [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
//    [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[SKStoreProductViewController class]]];
//    
    
    SKStoreProductViewController *store = [[SKStoreProductViewController alloc] init];
    store.delegate = self;
    NSDictionary<NSString *, id> *parameters = @{SKStoreProductParameterITunesItemIdentifier: appid};
    
    [store loadProductWithParameters:parameters completionBlock:^(BOOL result, NSError *error) {
        
        // finish loading
        [SVProgressHUD dismiss];
        
        if (error) {
            
            NSLog(@"error %@ with userInfo %@", error, [error userInfo]);
            
            // 提示用戶發(fā)生了錯誤
//             或者通過 URL 打開 AppStore App.
            NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/in/app/id%@",HLMAPPID]];
            [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:NULL];
            
            
        } else {
            
            [self presentViewController:store animated:YES completion:NULL];
        }
    }];
}

/// 用戶點擊取消會執(zhí)行該方法
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
    [viewController dismissViewControllerAnimated:YES completion:NULL];
}

3.SKStoreProductViewController只能通過 modal 方式打開,否則會報錯

二.通過openURL:options:completionHandler:方式,使用 scheme 為 itms-apps:// (push 樣式的) 啟動App Store應用 打開下載界面

    //push 樣式的 App Store應用 打開下載界面 scheme > itms-apps://
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%@",HLMAPPID]];
    [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:NULL];

三.通過openURL:options:completionHandler:方式,使用 scheme 為 https://(push 樣式的) 啟動App Store應用 打開下載界面

//push 樣式的 App Store應用 打開下載界面 scheme > https://
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/in/app/id%@",HLMAPPID]];
    [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:NULL];
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

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

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