一款快速實現微信認證的framework written in Swift
Getting Started
- CocoaPods </ul>
pod 'WechatKit'
- Carthage </ul>
github "starboychina/WechatKit"
Setting
-
設置URL scheme
在Xcode中,選擇你的工程設置項,選中“TARGETS”一欄,在“info”標簽欄的“URL type“添加“URL scheme”為你在微信開放平臺,注冊的應用程序id
-
IOS9以后 需要添加weixin到白名單
添加以下內容到info.plist
<key>LSApplicationQueriesSchemes</key> <array> <string>wechat</string> <string>weixin</string> </array>
-
重寫AppDelegate的handleOpenURL和openURL方法:
在AppDelegate.swift中添加import WechatKit
func application(application: UIApplication, handleOpenURL url: NSURL) -> Bool { return self.application(application, openURL: url, sourceApplication: nil, annotation: []) } func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { return WechatManager.sharedInstance.handleOpenURL(url) }
Usage
- 注冊app
WechatManager.appid = "微信開放平臺,注冊的應用程序id" WechatManager.appSecret = "微信開放平臺,注冊的應用程序Secret"
- 檢測微信是否安裝
WechatManager.sharedInstance.isInstalled()
- 使用微信認證
WechatManager.sharedInstance.authDelegate = self WechatManager.sharedInstance.checkAuth()
- 分享到微信
WechatManager.sharedInstance.shareDelegate = self /** 分享 - parameter scence: 請求發送場景 - parameter image: 消息縮略圖 - parameter title: 標題 - parameter description: 描述內容 - parameter url: 地址 - parameter extInfo: app分享信息(點擊分享內容返回程序時,會傳給WechatManagerShareDelegate.showMessage(message: String) */ WechatManager.sharedInstance.share(scence: WXScene, image: UIImage?, title: String, description: String, url: String? = default, extInfo: String? = default)
- Delegation
func checkIfNeeded(completion: ((res: AnyObject?, errCode: Int?) -> ())) -> Bool func signupIfNeeded(parameters: [String : AnyObject], completion: ((res: AnyObject) -> ())) func success(res: AnyObject) func failure(errCode: Int)
func showMessage(message: String)
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!