ios 显示其他app的购买页面
2016-06-13 15:44
309 查看
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
相关文章推荐
- IOS相机字体英文转中文
- 怎样在Android中使用Loaders
- android项目重构之mvp
- android项目重构之mvp
- android项目重构之mvp
- android项目重构之mvp
- android项目重构之mvp
- android项目重构之mvp
- Android中OnScrollListener的详解(Listview分批加载用到
- Unity读取 JSon配置文件
- Unity读取 JSon配置文件
- iOS开发-Could not find a storyboard named 'Main' in bundle NSBundle
- The content of element type "web-app" must match "
- Android动画开发实践
- 第1个Android应用程序 Android制作简单单页导航
- iOS 怎样判断解屏和锁屏状态
- LruCache缓存
- iOS 开发 车牌识别
- java.lang.NoSuchMethodError: android.graphics.drawable.VectorDrawable_Delegate.nDraw(JJJLandroid/gra
- 解决使用`SwipeRefreshLayout`下拉刷新和左右滑动事件冲突的问题