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/