The Skstoreproductviewcontroller class is a subclass of Uiviewcontroller, if you are familiar with the view controller, The Skstoreproductviewcontroller is also very easy to use. When you want to show users the products in the App Store, you need to:
1. Instantiation of a Skstoreproductviewcontroller class
2. Set its delegate
3. Display the Sotre product view controller to the consumer
The rest is left to the operating system to deal with. One point to remember is that Skstoreproductviewcontroller can only be displayed in a modal way. The Skstoreproductviewcontrollerdelegate protocol defines a separate method-productviewcontrollerdidfinish: This method is invoked when a consumer leaves the App store- Usually by clicking the Cancel button in the upper left corner screen. By sending Productviewcontrollerdidfinish to the agent: message, the operating system returns control to your program. Of course, you can't forget to support only IOS6.0 and more.
. h
#import <Foundation/Foundation.h>
@interface inlineappstore:nsobject
+ (inlineappstore*) sharedinstance;
-(void) Showappinapp: (NSString *) _appid;
@end
. m
#import "InlineAppstore.h" #import "AppDelegate.h" #import <StoreKit/StoreKit.h> @interface Inlineappstore ()
<SKStoreProductViewControllerDelegate> @end @implementation Inlineappstore + (inlineappstore*) sharedinstance {
static inlineappstore* Pinlineappstore = nil;
@synchronized (self) {if (Pinlineappstore = nil) {Pinlineappstore = [[Self alloc] init];
} return Pinlineappstore;
}-(void) Showappinapp: (NSString *) _appid {Class STOREVC = nsclassfromstring (@ "Skstoreproductviewcontroller");
if (Storevc!= nil) {Skstoreproductviewcontroller *_sksvc = [[Skstoreproductviewcontroller alloc] init];
_sksvc.delegate = self; [_sksvc loadproductwithparameters:@{skstoreproductparameteritunesitemidentifier: _appId} complet ionblock:^ (BOOL result, Nserror *error) {if (result) {[ Appdelegate Getinstance].navcoNtroller presentviewcontroller:_sksvc
Animated:yes Completion:nil];
} else{NSLog (@ "%@", error);
}
}]; } else{//below iOS6 does not have this class nsstring *_idstr = [NSString stringwithformat:@] itms-apps://itunes.apple.com/us/
App/id%@?mt=8 ", _appid];
[[UIApplication sharedapplication] Openurl:[nsurl Urlwithstring:_idstr]]; }} #pragma mark-skstoreproductviewcontrollerdelegate-(void) Productviewcontrollerdidfinish: (
Skstoreproductviewcontroller *) Viewcontroller {[Viewcontroller dismissviewcontrolleranimated:yes completion:nil];}