IOS6 App Store directly, without switching to App Store app

Source: Internet
Author: User

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];}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.