Display and download apps in IOS apps (storekit demo)

Source: Internet
Author: User

Recently, I was asked that a browser can display and download the application directly in the application, as well as how the download progress is achieved. I know it was implemented by sotrekit of ios6, however, I am still asked if there are examples. What I think is a very simple stuff? Followed by the following:

The procedure is simple:
1. Add storekit. Framework
2. reference the header file and declare the Protocol

# Import <storekit/storekit. h>

@ Interface viewcontroller () <skstoreproductviewcontrollerdelegate>

@ End

3. Several Simple implementationsCode

-(Ibaction) doloadanapp :( uibutton *) sender {

[Self openappwithid: @ "443795458"];

}

-(Void) openappwithid :( nsstring *) _ appid {

Class storevc = nsclassfromstring (@ "skstoreproductviewcontroller ");

If (storevc! = Nil ){

Skstoreproductviewcontroller * _ sksvc = [[skstoreproductviewcontroller alloc] init];

_ Sksvc. Delegate = self;

[_ Sksvc loadproductwithparameters: @ {skstoreproductparameteritunesitemidentifier: _ appid}

Completionblock: ^ (bool result, nserror * error ){

If (result ){

[Self presentviewcontroller: _ sksvc

Animated: Yes

Completion: Nil];

}

Else {

Nslog (@ "% @", error );

}

}];

}

Else {

// This class is not available below ios6

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

}

That's all
By the way, if you want to test the download process, you need to create a test account and then use that account to download the download process. Otherwise, the installation will fail.
In addition, it is obvious that "lower than ios6" refers to ios5, because this type only provides block implementation and can only be used in 4. more than X, and now Apple requires 4. X only supports 4.3, so many people give up 4.3 and only support 5. X or above?

Download project: storekittest

Reprinted: http://blog.cnrainbird.com/index.php/2013/02/02/ios_ying_yong_nei_zhan_shi_ying_yong_bing_xia_zai_storekit_demo/

Related Article

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.