ios 显示其他app的购买页面
using UnityEngine; using System.Collections; using System.Runtime.InteropServices ; public class IOSDoor : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { } [DllImport("__Internal")] private static extern void ShowBook ( int bookid ); public static void ActivateButton0 () { Debug.Log (2333); if (Application.platform != RuntimePlatform.OSXEditor) { //点击按钮后调用xcode中的 _PressButton0 ()方法, //方法中的内容须要我们自己来添加 ShowBook (1073005459); } } [DllImport("__Internal")] private static extern void _ShowBookApp ( string bookid ); public static void ShowBookApp (string bookid ) { Debug.Log (2333 + "ShowBookStr" + bookid); if (Application.platform != RuntimePlatform.OSXEditor) { //点击按钮后调用xcode中的 _PressButton0 ()方法, //方法中的内容须要我们自己来添加 _ShowBookApp ("1073005459"); } } }
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
..............................
NSLog(@"eeee") ; UnityViewController * uv = [[UnityViewController alloc] init] ; //[uv.view setFrame:CGRectMake(0, 200, 320, 200)]; //uv.view.backgroundColor = [UIColor blackColor]; [UnityGetGLViewController().view addSubview:uv.view] ; [UnityViewController setInstance:uv]; return YES; }
// // UnityViewController.h // Unity-iPhone // // Created by lc—— on 16/6/13. // // #import <UIKit/UIKit.h> #import <StoreKit/StoreKit.h> @interface UnityViewController : UIViewController<SKStoreProductViewControllerDelegate> - (void)showStoreProductInApp:(NSString *)appID ; +(void) setInstance: ( UnityViewController *) inst ; +(UnityViewController *) getInstance ; @end
// // UnityViewController.m // Unity-iPhone // // Created by lc—— on 16/6/13. // // #import "UnityViewController.h" @interface UnityViewController () @end @implementation UnityViewController void ShowBook( int bookID ) { NSLog(@"rrrrr") ; //[[UnityViewController getInstance] showStoreProductInApp:@"1073005459"]; [[UnityViewController getInstance] showStoreProductInApp:[NSString stringWithFormat:@"%d" , bookID]]; } void _ShowBookApp( const char * bookID ) { NSString * bookIDStr = [NSString stringWithUTF8String:bookID] ; NSLog(@"rrrr r --- %@" , bookIDStr) ; [[UnityViewController getInstance] showStoreProductInApp:@"1073005459"]; // NSString * bookIDStr = [NSString stringWithUTF8String:bookID] ; //[[UnityViewController getInstance] showStoreProductInApp:bookIDStr]; } void _ShowBookStar( const char * bookID ) { NSLog(@"rrrrr") ; // //[[UnityViewController getInstance] showStoreProductInApp:@"1073005459"]; NSString * bookIDStr = [NSString stringWithUTF8String:bookID] ; [[UnityViewController getInstance] loadAppStoreController:bookIDStr]; } static UnityViewController * instance ; +(UnityViewController *) getInstance { return instance ; } +(void) setInstance: ( UnityViewController *) inst { instance = inst ; } - (void)viewDidLoad { [super viewDidLoad]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)loadAppStoreController:(NSString *)appID { NSLog(@"rrrrr--loadAppStoreController") ; // 初始化控制器 SKStoreProductViewController *storeProductViewContorller = [[SKStoreProductViewController alloc] init]; // 设置代理请求为当前控制器本身 storeProductViewContorller.delegate = self; [storeProductViewContorller loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:appID} completionBlock:^(BOOL result, NSError *error) { if(error) { NSLog(@"error %@ with userInfo %@",error,[error userInfo]); } else { // 模态弹出appstore [self presentViewController:storeProductViewContorller animated:YES completion:^{ }]; } }]; } - (void)showStoreProductInApp:(NSString *)appID{ Class isAllow = NSClassFromString(@"SKStoreProductViewController"); NSLog(@"ttt") ; if (isAllow != nil) { SKStoreProductViewController *sKStoreProductViewController = [[SKStoreProductViewController alloc] init]; [sKStoreProductViewController.view setFrame:CGRectMake(0, 200, 320, 200)]; [sKStoreProductViewController setDelegate:self]; [sKStoreProductViewController loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier: appID} completionBlock:^(BOOL result, NSError *error) { if (result) { [self presentViewController:sKStoreProductViewController animated:YES completion:nil]; // [self removeNotice]; }else{ NSLog(@"error:%@",error); } }]; }else{ //低于iOS6的系统版本没有这个类,不支持这个功能 NSString *string = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/xxxxxxx/app/id%@?mt=8",appID]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]]; } } #pragma mark - SKStoreProductViewControllerDelegate - (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController { [viewController dismissViewControllerAnimated:YES completion:nil]; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end