从iphone应用程序链接到iBook商店中的书籍

mos*_*fya 2 iphone xcode itunes objective-c ios

环顾四周后,我无法直接回答以下情况:我可以从iphone应用程序链接到iBook商店中的书籍,而无需集成应用内购买API吗?

据我所知,iBooks确实会收取你放置书籍的费用,所以我的逻辑说它应该是可能的,否则你将被收取两次费用.

非常感谢.

bry*_*yle 8

如果您的应用程序定位到iOS 6.0,则可以使用新SKStoreProductViewController功能允许用户直接从您的应用购买iTunes,App Store和iBooks内容,而无需离开.

以下是如何从中呈现它UIViewController.您必须 StoreKit.framework 添加到您的应用程序.

ViewController.h

#import <StoreKit/StoreKit.h>

@interface UIViewController : UIViewController <SKStoreProductViewControllerDelegate>

@end
Run Code Online (Sandbox Code Playgroud)

ViewController.m

-(void)showProductPageForProductID:(NSInteger)productID {

    SKStoreProductViewController *sv = [[SKStoreProductViewController alloc] init];
    sv.delegate = self;

    NSDictionary *product = @{ SKStoreProductParameterITunesItemIdentifier: @(productID)};
    [sv loadProductWithParameters:product completionBlock:^(BOOL result, NSError *error) {

            if(result)
                [self presentModalViewController:sv animated:YES];
            else {
               //product not found, handle appropriately
            }
        }];

}    
-(void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
            [viewController dismissModalViewControllerAnimated:YES];
 }
Run Code Online (Sandbox Code Playgroud)

如果你的目标设备低于iOS 6.0,你可以使用它:

 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/us/book/the-casual-vacancy/id518781282?mt=11"]];
Run Code Online (Sandbox Code Playgroud)

只需用您的链接替换该URL字符串,它就会离开您的应用程序并进入显示该产品的iBooks应用程序.

如果要同时定位iOS 6.0及更低版本,可以SKStoreProductViewController使用以下条件来检查它们是否具有新内容

 if([SKStoreProductViewController class]) {
     //show the SKStoreProductViewController
}
else {
     //use UIApplication's openURL:
}
Run Code Online (Sandbox Code Playgroud)

要获取产品的Apple产品ID,您只需检查产品的URL,例如:

http://itunes.apple.com/us/book/the-casual-vacancy/id518781282?mt=11

产品ID是518781282.它id位于URL中的部分之后.不要包含之后的?任何内容.