移动端微信接入
This commit is contained in:
1 parent
ca91f45ef3
commit
31e8e3bebb
32 files changed
+17241
-9
No files matched your search
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// NativeBridge.m
|
||||
// Unity-iPhone
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#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) {}];
|
||||
}
|
||||
|
||||
// 分享图片至微信
|
||||
void ShareImgToWX(int scene, UInt8 *msgByteArrayData, int arrayLength, const char* title, const char* description){
|
||||
WXImageObject *imageObject = [WXImageObject object];
|
||||
imageObject.imageData = [[NSData alloc] initWithBytes:msgByteArrayData length:arrayLength];
|
||||
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 = 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];
|
||||
}
|
||||
Reference in new issue
Block a user