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