WZShareKit 2.1.1

WZShareKit 2.1.1

qiuqixiang 维护。



  • 作者
  • LiuSky

我主良缘分享组件

要求

  • iOS 9.0+
  • Xcode 10.0+
  • Swift 5.0+

CocoaPods 安装

pod 'WZShare', '~> 1.0.0'

分享

示例:分享到微信(微信):

  1. 在项目目标 Info.plist 中,设置 URL TypeLSApplicationQueriesSchemes 如下

  2. 注册账户:// 这里不需要这样做,但为了方便

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    
        MonkeyKing.registerAccount(.weChat(appID: "xxx", appKey: "yyy", miniAppID: nil))
    
        return true
    }
  3. 如果您需要处理回调,请向您的 AppDelegate 中添加以下代码

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    //func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool { // only for iOS 8
    
        if MonkeyKing.handleOpenURL(url) {
            return true
        }
    
        return false
    }

  4. 准备您的消息并让 MonkeyKing 传递它

    @IBAction func shareURLToWeChatSession(sender: UIButton) {
    
        MonkeyKing.registerAccount(.weChat(appID: "xxx", appKey: "yyy", miniAppID: nil)) // you can do it here (just before deliver)
    
        let message = MonkeyKing.Message.weChat(.session(info: (
            title: "Session",
            description: "Hello Session",
            thumbnail: UIImage(named: "rabbit"),
            media: .url(URL(string: "http://www.apple.com/cn")!)
        )))
    
        MonkeyKing.deliver(message) { success in
            print("shareURLToWeChatSession success: \(success)")
        }
    }

完成!

OAuth

示例:微博OAuth

MonkeyKing.oauth(for: .weibo) { (oauthInfo, response, error) -> Void in
    print("OAuthInfo \(oauthInfo) error \(error)")
    // Now, you can use the token to fetch info.
}

或仅代码的微信OAuth

MonkeyKing.weChatOAuthForCode { [weak self] (code, error) in
    guard let code = code else {
        return
    }
    // TODO: fetch info with code
}

如果用户没有在设备上安装微博App,则MonkeyKing将使用网页OAuth

支付

示例:支付宝

let order = MonkeyKing.Order.alipay(urlString: urlString, scheme: nil)
MonkeyKing.deliver(order) { result in
    print("result: \(result)")
}

您需要配置远程服务器上的pay.php。在示例项目中可以找到关于pay.php的示例。


启动微信小程序

let path = "..."
MonkeyKing.launch(.weChat(.miniApp(username: "gh_XXX", path: path, type: .release))) { result in
    switch result {
    case .success:
        break
    case .failure(let error):
        print("error:", error)
    }
}

注意,用户名有gh_前缀(原始ID)。

更多

如果您想使用UIActivityViewController进行分享,MonkeyKing有AnyActivity可以帮助您。

查看示例以获取更多信息。

参考

许可

WZShare遵循MIT许可证发布。更多信息请参阅LICENSE