因为我也不是IOS开发者,此文章仅仅为了记录过程。
1. 首先,在Unity下面建立一个类,代码如下(命名什么的都是随便的):
using UnityEngine;
using System.Runtime.InteropServices;
public class PayBuildIOS {
#if UNITY_IPHONE
[DllImport ("__Internal")]
#endif
private static extern int IOSPay(string message, string title);
public static void TestPay()
{
#if UNITY_IPHONE
Debug.Log(IOSPay("Hello", "World"));
#endif
}
}
在一个按钮的点击事件里面调用TestPay的方法就好了。
2. 然后把整个项目导出Xcode项目,然后在Class组里面建两个类(一个.h, 一个.mm(一开始是.m的,直接改就好))):
然后就得到下面的目录
3. 两个类的代码如下:
//
// IOSPayManage.h
// Unity-iPhone
//
// Created by Louis on 15-9-9.
//
//
#import <Foundation/Foundation.h>
@interface IOSPayManage : NSObject
@end
//
// IOSPayManage.m
// Unity-iPhone
//
// Created by Louis on 15-9-9.
//
//
#import "IOSPayManage.h"
extern "C"
{
int IOSPay(const char *message, const char *title);
}
int IOSPay(const char *message, const char *title)
{
UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:[NSString stringWithUTF8String:title] message:[NSString stringWithUTF8String:message] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertView show];
return 1234;
}
@implementation IOSPayManage
@end
4. 然后就运行测试到真机上就可以看到点击弹出效果了。
PS。其实我是打算做IOS 的 IAP功能的,到时候再写那个教程吧。
仅此记录。