Swift App跳转到微信小程序

1、微信开放平台添加应用并关联小程序

image.png

2、微信开放平台SDK集成

SDK下载地址:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419319164&token=&lang=zh_CN

3、AppDelegate.swift

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder,UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    WXApi.registerApp("微信开放平台的AppID")
    return true
}

/// iOS 8 及以下
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    return WXApi.handleOpen(url, delegate: self)
}

/// iOS 9 及以上
func application(_ application: UIApplication, open url: URL, sourceApplication: String?,   annotation: Any) -> Bool {
      return WXApi.handleOpen(url, delegate: self)
  }
}

extension AppDelegate: WXApiDelegate {
  func onReq(_ req: BaseReq) {}
  func onResp(_ resp: BaseResp) {}
}

4、info.plist文件设置白名单

image.png

5、TARGETS-info设置微信小程序APPID

image.png

6、调起微信小程序

image.png

你可能感兴趣的:(Swift App跳转到微信小程序)