Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux 程式設計 >> Linux 程式設計

iOS 6 新功能:在 App 內直接展示 App Store 頁面

iOS 6 提供的 SKStoreProductViewController 讓 App 可以在自己的流程中打開 App Store 的應用介紹頁,使用者不必跳出應用。

1. 匯入函式庫

#import <StoreKit/StoreKit.h>

2. 在點擊事件中載入商品頁

- (IBAction)gotoStore:(id)sender {
    // Initialize Product View Controller
    SKStoreProductViewController *storeProductViewController =
        [[SKStoreProductViewController alloc] init];
    // Configure View Controller
    [storeProductViewController setDelegate:self];

    [storeProductViewController loadProductWithParameters:
        @{SKStoreProductParameterITunesItemIdentifier : @"594467299"}
        completionBlock:^(BOOL result, NSError *error) {
            if (error) {
                NSLog(@"Error %@ with User Info %@.", error, [error userInfo]);
            } else {
                // Present Store Product View Controller
                [self presentViewController:storeProductViewController
                                   animated:YES completion:nil];
            }
        }];
}

3. 實作委派方法

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
    __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_6_0)
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

4. 測試

這個元件只能在真機上驗證,模擬器不會有反應。實測即可看到應用內嵌的 App Store 頁面,並由 productViewControllerDidFinish 負責關閉。

Copyright © Linux教程網 All Rights Reserved