2021-08-23 09:28:14 +08:00
|
|
|
|
//
|
|
|
|
|
|
// NativeBridge.m
|
|
|
|
|
|
// Unity-iPhone
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
2021-10-13 19:03:14 +08:00
|
|
|
|
#import <CoreLocation/CoreLocation.h>
|
2021-08-23 09:28:14 +08:00
|
|
|
|
#import "WXApi.h"
|
|
|
|
|
|
|
|
|
|
|
|
//这是向微信终端注册你的appid
|
|
|
|
|
|
void RegisterApp(const char* appid)
|
|
|
|
|
|
{
|
|
|
|
|
|
NSString *weichatId = [NSString stringWithFormat:@"%s", appid];
|
|
|
|
|
|
|
|
|
|
|
|
BOOL installed = [WXApi isWXAppInstalled];
|
|
|
|
|
|
NSLog(@"installed result: %@", installed?@"true":@"false");
|
|
|
|
|
|
|
|
|
|
|
|
BOOL result = [WXApi registerApp:weichatId universalLink:(@"https://wx.powerfun.com.cn/pf2/")];
|
|
|
|
|
|
|
|
|
|
|
|
NSLog(@"result: %@", result?@"true":@"false");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 调起小程序
|
|
|
|
|
|
void LaunchMiniProgram(const char* miniProgramID, const char* path){
|
|
|
|
|
|
WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
|
|
|
|
|
|
launchMiniProgramReq.userName = [NSString stringWithUTF8String:miniProgramID]; //拉起的小程序的username
|
|
|
|
|
|
launchMiniProgramReq.path = [NSString stringWithUTF8String:path]; ////拉起小程序页面的可带参路径,不填默认拉起小程序首页,对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar"。
|
|
|
|
|
|
launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
|
|
|
|
|
|
[WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {}];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 分享图片至微信
|
2021-12-10 18:10:20 +08:00
|
|
|
|
void ShareImgToWX(int scene, UInt8 *msgByteArrayData, int arrayLength){
|
2021-08-23 09:28:14 +08:00
|
|
|
|
WXImageObject *imageObject = [WXImageObject object];
|
|
|
|
|
|
imageObject.imageData = [[NSData alloc] initWithBytes:msgByteArrayData length:arrayLength];
|
|
|
|
|
|
WXMediaMessage *message = [WXMediaMessage message];
|
2021-12-10 18:10:20 +08:00
|
|
|
|
// message.title = [NSString stringWithUTF8String:title];
|
|
|
|
|
|
// message.description = [NSString stringWithUTF8String:description];
|
2021-08-23 09:28:14 +08:00
|
|
|
|
// 用APP的Icon做缩略图
|
|
|
|
|
|
NSDictionary *infoPlist = [[NSBundle mainBundle] infoDictionary];
|
|
|
|
|
|
NSString *icon = [[infoPlist valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"] lastObject];
|
|
|
|
|
|
[message setThumbImage:[UIImage imageNamed:icon]];
|
|
|
|
|
|
message.mediaObject = imageObject;
|
|
|
|
|
|
SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
|
|
|
|
|
|
req.bText = NO;
|
|
|
|
|
|
req.message = message;
|
|
|
|
|
|
req.scene = scene;
|
|
|
|
|
|
[WXApi sendReq:req completion:nil];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 分享链接至微信
|
|
|
|
|
|
void ShareUrlToWX(int scene, const char* url, const char* title, const char* description){
|
|
|
|
|
|
WXWebpageObject *webpageObject = [WXWebpageObject object];
|
|
|
|
|
|
webpageObject.webpageUrl = [NSString stringWithUTF8String:url];
|
|
|
|
|
|
WXMediaMessage *message = [WXMediaMessage message];
|
|
|
|
|
|
message.title = [NSString stringWithUTF8String:title];
|
|
|
|
|
|
message.description = [NSString stringWithUTF8String:description];
|
|
|
|
|
|
// 用APP的Icon做缩略图
|
|
|
|
|
|
NSDictionary *infoPlist = [[NSBundle mainBundle] infoDictionary];
|
|
|
|
|
|
NSString *icon = [[infoPlist valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"] lastObject];
|
|
|
|
|
|
[message setThumbImage:[UIImage imageNamed:icon]];
|
|
|
|
|
|
message.mediaObject = webpageObject;
|
|
|
|
|
|
SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
|
|
|
|
|
|
req.bText = NO;
|
|
|
|
|
|
req.message = message;
|
|
|
|
|
|
req.scene = scene;
|
|
|
|
|
|
[WXApi sendReq:req completion:nil];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//判断是否安装微信
|
|
|
|
|
|
bool IsWechatInstalled_iOS()
|
|
|
|
|
|
{
|
|
|
|
|
|
return [WXApi isWXAppInstalled];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//微信登录
|
|
|
|
|
|
void WechatLogin(const char* scope,const char* state)
|
|
|
|
|
|
{
|
|
|
|
|
|
//登录
|
|
|
|
|
|
SendAuthReq* req = [[SendAuthReq alloc] init];
|
|
|
|
|
|
req.scope = [NSString stringWithUTF8String:scope];
|
|
|
|
|
|
req.state = [NSString stringWithUTF8String:state];
|
|
|
|
|
|
[WXApi sendReq:req completion:nil];
|
|
|
|
|
|
}
|
|
|
|
|
|
//打开微信(注意:需要先注册appid)
|
|
|
|
|
|
void OpenWXApp()
|
|
|
|
|
|
{
|
|
|
|
|
|
[WXApi openWXApp];
|
2021-08-26 15:08:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-09 15:44:28 +08:00
|
|
|
|
bool checkAPPIsExist(const char * URLScheme)
|
2021-08-26 15:08:02 +08:00
|
|
|
|
{
|
|
|
|
|
|
NSURL* url;
|
2021-09-09 15:44:28 +08:00
|
|
|
|
NSString * urls = [NSString stringWithUTF8String:URLScheme];
|
|
|
|
|
|
if ([urls containsString:@"://"])
|
2021-08-26 15:08:02 +08:00
|
|
|
|
{
|
2021-09-09 15:44:28 +08:00
|
|
|
|
url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",urls]];
|
2021-08-26 15:08:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-09-09 15:44:28 +08:00
|
|
|
|
url = [NSURL URLWithString:[NSString stringWithFormat:@"%@://",urls]];
|
2021-08-26 15:08:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
if([[UIApplication sharedApplication] canOpenURL:url])
|
|
|
|
|
|
{
|
|
|
|
|
|
return YES;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return NO;
|
|
|
|
|
|
}
|
2021-10-13 19:03:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
bool checkLocation()
|
|
|
|
|
|
{
|
|
|
|
|
|
return [CLLocationManager locationServicesEnabled] == YES;
|
2021-08-23 09:28:14 +08:00
|
|
|
|
}
|