All Projects → Xinguang → Wechatkit

Xinguang / Wechatkit

Licence: mit
一款快速实现微信第三方登录的框架(Swift版) SDK 1.8.5

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Wechatkit

Swiftinstagram
Instagram API client written in Swift
Stars: ✭ 570 (+128.92%)
Mutual labels:  cocoapods, carthage, authentication
Tbactionsheet
A Custom&Powerful Action Sheet For iOS. 一个 ActionSheet 满足所有样式!超高自由度的可定制!
Stars: ✭ 942 (+278.31%)
Mutual labels:  cocoapods, carthage, wechat
Auth0.swift
Swift toolkit for Auth0 API
Stars: ✭ 146 (-41.37%)
Mutual labels:  cocoapods, carthage, authentication
Sensor Visualizer Kit
Visualize iOS sensors for live presentations, iOS AppStore demos, Apple Store prototypes, design reviews.
Stars: ✭ 242 (-2.81%)
Mutual labels:  cocoapods, carthage
Amplitude Ios
Native iOS/tvOS/macOS SDK
Stars: ✭ 216 (-13.25%)
Mutual labels:  cocoapods, carthage
Tutti
Tutti is a Swift library that lets you create tutorials, hints and onboarding experiences.
Stars: ✭ 224 (-10.04%)
Mutual labels:  cocoapods, carthage
Wechat Jump Game
😊 Nodejs 微信《跳一跳》辅助
Stars: ✭ 216 (-13.25%)
Mutual labels:  wechat, weixin
Gifu
High-performance animated GIF support for iOS in Swift
Stars: ✭ 2,703 (+985.54%)
Mutual labels:  cocoapods, carthage
Admozaiccollectionviewlayout
ADMozaicCollectionViewLayout is yet another UICollectionViewLayout subclass that implements "brick", "mozaic" or Pinterest style layout.
Stars: ✭ 226 (-9.24%)
Mutual labels:  cocoapods, carthage
Swipycell
Easy to use UITableViewCell implementing swiping to trigger actions.
Stars: ✭ 230 (-7.63%)
Mutual labels:  cocoapods, carthage
Pinche xcx data
同城拼车微信小程序后端代码
Stars: ✭ 244 (-2.01%)
Mutual labels:  wechat, weixin
Fusuma
Instagram-like photo browser and a camera feature with a few line of code in Swift.
Stars: ✭ 2,434 (+877.51%)
Mutual labels:  cocoapods, carthage
Pincache
Fast, non-deadlocking parallel object cache for iOS, tvOS and OS X
Stars: ✭ 2,513 (+909.24%)
Mutual labels:  cocoapods, carthage
Alertift
Swifty, modern UIAlertController wrapper.
Stars: ✭ 242 (-2.81%)
Mutual labels:  cocoapods, carthage
Aksidemenu
Beautiful iOS side menu library with parallax effect. Written in Swift
Stars: ✭ 216 (-13.25%)
Mutual labels:  cocoapods, carthage
Sync
JSON to Core Data and back. Swift Core Data Sync.
Stars: ✭ 2,538 (+919.28%)
Mutual labels:  cocoapods, carthage
Swiftpagemenu
Customizable Page Tab Menu Controller 👍
Stars: ✭ 233 (-6.43%)
Mutual labels:  cocoapods, carthage
Weapp Workflow
基于Gulp 的微信小程序前端开发工作流 💯
Stars: ✭ 241 (-3.21%)
Mutual labels:  wechat, weixin
Sdk3rd
第三方SDK集成库,授权/分享/支付
Stars: ✭ 249 (+0%)
Mutual labels:  wechat, weixin
Iso8601
ISO8601 date parser and writer
Stars: ✭ 213 (-14.46%)
Mutual labels:  cocoapods, carthage

WechatKit

Build Status Swift version Documentation SwiftLint Carthage compatible CocoaPods Compatible License MIT GitHub release FOSSA Status


Getting Started

  • CocoaPods
pod 'WechatKit'
  • Carthage

安装Carthage

github "starboychina/WechatKit"

Setting

  • 设置URL scheme

    在Xcode中,选择你的工程设置项,选中“TARGETS”一栏,在“info”标签栏的“URL type“添加“URL scheme”为你在微信开放平台,注册的应用程序id

Setting

  • IOS9以后 需要添加weixin到白名单(如图)

    或以源代码方式打开info.plist, 并添加以下内容.

	<key>LSApplicationQueriesSchemes</key>
	<array>
		<string>wechat</string>
		<string>weixin</string>
	</array>

Setting

  • AppDelegate的handleOpenURL和openURL方法:

    在AppDelegate.swift中添加import WechatKit

    /// iOS 9 以后将弃用 请用下面的方法 #20
    /// -> NS_DEPRECATED_IOS(4_2, 9_0, "Please use application:openURL:options:") __TVOS_PROHIBITED;
    func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        return WechatManager.shared.handleOpenURL(url)
        // 如需要使用其他第三方可以 使用 || 连接 其他第三方库的handleOpenURL
        // return WechatManager.shared.handleOpenURL(url) || TencentOAuth.HandleOpenURL(url) || WeiboSDK.handleOpenURL(url, delegate: SinaWeiboManager.shared) ......
    }
    /// iOS 9.0 以后请使用这个方法
    /// Please use this (application:openURL:options:)
    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        return WechatManager.shared.handleOpenURL(url)
        // 如需要使用其他第三方可以 使用 || 连接 其他第三方库的handleOpenURL
        // return WechatManager.shared.handleOpenURL(url) || TencentOAuth.HandleOpenURL(url) || WeiboSDK.handleOpenURL(url, delegate: SinaWeiboManager.shared) ......
    }

Usage

  • 注册app
  WechatManager.appid = "微信开放平台,注册的应用程序id"
  WechatManager.appSecret = "微信开放平台,注册的应用程序Secret"
  • 检测微信是否安装
  WechatManager.shared.isInstalled()
  • 使用微信登录

    默认会记住openid,以及access_token,在token还在有效期时,调用checkAuth则不会打开微信客户端,直接使用token和微信服务器获取认证信息

    WechatManager.shared.checkAuth { result in
        switch result {
        case .failure(let errCode)://登录失败
            print(errCode)
        case .success(let value)://登录成功 value为([String: String]) 从微信返回的openid access_token 以及 refresh_token
            print(value) //当前是在子线程,如需回到主线程调用 DispatchQueue.main.async { print(value) }
        }
    }
  • [注意]

    • 如果没有安装微信客户端,则会弹出 webview, 通过输入已绑定微信的手机号, 来接收认证短信, 然后在手机浏览器中, 打开认证短信中的地址 (类似于:wxd930ea5d5a258f4f://wapoauth?m=KzgxNzAxMzExMTY2Ng%3D%3D&t=xxxx xxxx为4位数字), 会自动跳回你的 APP, 并且实现登录功能.

    • 如果是 iPad 则不支持短信认证, 建议在 iPad 上接入微信登录时,先检测用户手机是否已安装微信客户端(使用WechatManager.shared.isInstalled()函数 ),对未安装的用户隐藏微信登录按钮,只提供其他登录方式(比如手机号注册登录、游客登录等)。

    iphone

    ipad

  • 获取微信用户信息

  WechatManager.shared.getUserInfo { result in
      switch result {
      case .failure(let errCode)://获取失败
          print(errCode)
      case .success(let value)://获取成功 value为([String: String]) 微信用户基本信息
          print(value) //当前是在子线程,如需回到主线程调用 DispatchQueue.main.async { print(value) }
      }
  }
  • 退出登录

    由于默认会记住openid,以及access_token,如需要切换用户则需要退出登录.

WechatManager.shared.logout()

  • 分享到微信
  WechatManager.shared.shareDelegate = self
  /**
  分享

  - parameter scence:      请求发送场景
  - parameter image:       消息缩略图
  - parameter title:       标题
  - parameter description: 描述内容
  - parameter url:         地址
  - parameter extInfo:     app分享信息(点击分享内容返回程序时,会传给WechatManagerShareDelegate.showMessage(message: String)
  */
  WechatManager.shared.share(scence: WXScene, image: UIImage?, title: String, description: String, url: String? = default, extInfo: String? = default)
  • Delegation

分享Delegation

    //app分享后 点击分享返回时调用
    func showMessage(message: String)

License

FOSSA Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].