iOS审核不让有支付代码,因此只使用轻度功能的话,能够不使用微信SDK。小程序
使用前须要先去微信开放平台绑定。微信
/** * 开发前须要到微信开放平台把App绑定小程序,而后在小程序的管理员微信上点击赞成绑定,就能够转跳了 * 字段解释: * @appid:小程序appid * @username:‘gh’开头的小程序公用id * @path:小程序须要打开页面的路径 * @type:0是正式版,1是开发版,2是体验版 **/ -(void)jumpToWechatMiniProgram:(NSString *)appid ghId:(NSString *)username path:(NSString *)path type:(NSString *)miniProgramtype{ NSString *mPath = [path stringByReplacingOccurrencesOfString:@"/" withString:@"%2F"]; NSString *url = [NSString stringWithFormat:@"weixin://app/%@/jumpWxa/?userName=%@&path=%@&miniProgramType=%@&extMsg=",appid,username,mPath,miniProgramtype]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]options:@{} completionHandler:^(BOOL success) { NSLog(@"跳转成功"); }]; }
-(IBAction)jumpWithUrl:(id)sender{ [self jumpToWechatMiniProgram:@"wx8888888888888" ghId:@"gh_88888888888" path:@"pages/index/index?session=本身定的参数" type:@"2"]; }
若是是真机测试记得在info.plist添加白名单session
<key>LSApplicationQueriesSchemes</key> <array> <string>mqzone</string> <string>sinaweibo</string> <string>mqqwpa</string> <string>mqqbrowser</string> <string>wtloginmqq2</string> <string>weixin</string> <string>wechat</string> </array>
iOS中,app互相转跳走的都是openUrl这个接口,经过scheme就能够转跳到目标程序,可是scheme是不审核的,能够随意指定,因此咱们能够经过写一个假微信(scheme是weixin
),来拦截微信SDK的启动请求,从而获取到对应的启动字符串,而后本身拼接字符串便可。app
在info.plist里添加(注意缩进不要弄错了,最好在模拟器上试,若是安装了微信,是不会跳到咱们的假微信里的。):测试
<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>weixin</string> </array> <key>CFBundleURLName</key> <string>1111</string> </dict> </array>
看不到源码页面的话,右键info.plist,选择Open As -> Source Code就能看到了,改完了切回Property List模式,不报错就说明格式是对的。url
在appDelegate.m里增长:code
// 这方法显示已经废弃了,可是只是获取参数仍是能够的 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{ //显示截取的urlscheme UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"接收到的urlScheme" message:url.absoluteString delegate:nil cancelButtonTitle:nil otherButtonTitles:@"肯定", nil]; [alert show]; // 复制到剪贴板 UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; pasteboard.string = url.absoluteString; return YES; }
而后就能看到弹窗里的urlscheme就能够了,只要拼接出一个同样的urlscheme,就能够启用微信SDK一样的功能。orm