VisitHealthSDK 版本 0.0.3

VisitHealthSDK 0.0.3

Yash维护。



  • 81799742

VisitHealthSDK

CI Status Version License Platform

示例

要运行示例项目,请克隆仓库,然后首先在Example目录中运行pod install

要求

  • 支持iOS版本>=12.0
  • 请确保您已在Info.plist文件中为以下用途添加了权限文本 - 隐私 - 健康共享使用描述,隐私 - 健康更新使用描述,隐私 - 摄像头使用描述,隐私 - 本地网络使用描述,隐私 - 麦克风使用描述
  • 在签名和功能中添加HealthKit
  • 在目标和功能签名的“后台模式”能力开启音频,Airplay和画中画
  • 项目需要添加cocoapods。请遵循以下文章将cocoapods添加到您的项目中。

安装

VisitHealthSDK可通过Visit私有Pod spec获取。要安装它,请将以下行添加到Podfile顶部

source 'https://github.com/VisitApp/visit-ios-pod-spec.git'
source 'https://cdn.cocoapods.org/'

然后,在Podfile中您的目标添加以下行

pod 'VisitHealthSDK'

用法

要使用SDK,您只需在AppDelegate中初始化VisitIosHealthController,并在视图控制器中导入此视图。请确保在viewDidLoad方法中添加已初始化的视图到您的main subview中。完成这些后,调用loadVisitWebUrl方法。

以下是一个示例代码,其中通过编程初始化了VisitIosHealthController-

//  AppDelegate.swift
import UIKit
import VisitHealthSDK

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    // add VisitSDK notification in the delegate's open method like below
    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        NotificationCenter.default.post(name: Notification.Name("VisitSDK"), object: nil, userInfo: ["deepLink":url])
        return true
    }

    // add the shared static method like below to import visitHealthView in your view controller
    static func shared() -> AppDelegate {
        return UIApplication.shared.delegate as! AppDelegate
    }
}


//  ViewController.swift
import UIKit
import VisitHealthSDK;

extension Notification.Name {
    static let customNotificationName = Notification.Name("VisitEventType")
}

// extend VisitVideoCallDelegate if the video calling feature needs to be integrated otherwise UIViewController can be used
class ViewController: VisitVideoCallDelegate {
    // required
    let visitHealthView = AppDelegate.shared().visitHealthView

    // initializing a viewcontroller vc
    let vc = UIViewController()
    var button2Title: String = ""
    var isHealthKitConnected = false;
    
    let button = UIButton(frame: CGRect(x: 20, y: 20, width: 200, height: 60))
    let button2 = UIButton(frame: CGRect(x: 20, y: 40, width: 200, height: 60))

    override func viewDidLoad() {
        super.viewDidLoad()

        // OPTIONAL : the health kit permission status can be obtained using the following callback
        visitHealthView.canAccessHealthKit{(value) -> () in
            if(value){
                print("health kit can be accessed")
            }else{
                print("health kit can't be accessed")
            }
        }

        // intializing visitHealthView's frame
        visitHealthView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)

        // initializing vc's view with visitHealthView
        vc.view = visitHealthView
        
        // show button programattically, in actual app this can be ignored
        self.showButton()
        
        // the notification observer
        NotificationCenter.default.addObserver(self, selector: #selector(self.methodOfReceivedNotification(notification:)), name: .customNotificationName, object: nil)
    }
    
    // show button programattically, in actual app this can be ignored
    @objc func showButton(){
       button.center = CGPoint(x: view.frame.size.width  / 2, y: view.frame.size.height / 4)
        button.setTitle("Open Visit app", for: .normal)
        button.backgroundColor = .blue
        button.setTitleColor(UIColor.white, for: .normal)
        button.addTarget(self, action: #selector(self.buttonTapped), for: .touchUpInside)
        self.view.addSubview(button)

        button2Title = visitHealthView.canAccessFitbit() ? "Disconnect from Fitbit" : "Connect to Fitbit"
        button2.center = CGPoint(x: view.frame.size.width  / 2, y: view.frame.size.height / 3)
        button2.setTitle(button2Title, for: .normal)
        button2.backgroundColor = .blue
        button2.setTitleColor(UIColor.white, for: .normal)
        button2.addTarget(self, action: #selector(self.button2Tapped), for: .touchUpInside)

        if(!self.isHealthKitConnected){
            self.view.addSubview(button2)
        }
    }
    
    // hide button programattically, in actual app this can be ignored
    @objc func hideButton(){
        button.removeFromSuperview()
        button2.removeFromSuperview()
    }

    @objc func button2Tapped(sender : UIButton) {
        if(visitHealthView.canAccessFitbit()){
            visitHealthView.revokeFitbitPermissions()
            self.hideButton()
        }else{
            self.buttonTapped(sender: sender)
        }
    }
    
   // notification observer
    @objc func methodOfReceivedNotification(notification: Notification) {
        let event = notification.userInfo?["event"] as! String
        let current = notification.userInfo?["current"] ?? ""
        let total = notification.userInfo?["total"] ?? ""
        let message = notification.userInfo?["message"] ?? ""
        let code = notification.userInfo?["code"] ?? ""
        switch(event){
            case "HealthKitConnectedAndSavedInPWA":
                print("health kit connected and saved")
            case "AskForFitnessPermission":
                print("health kit permission requested")
            case "FitnessPermissionGranted":
                print("health kit permission granted")
            case "FitbitPermissionGranted":
                print("Fitbit permission granted")
            case "FibitDisconnected":
                DispatchQueue.main.async {
                   self.showButton()
                }
                print("Fitbit permission revoked")
            case "HRA_Completed":
                print("hra completed")
            case "StartVideoCall":
                print("start video call")
            case "HRAQuestionAnswered":
                print("HRAQuestionAnswered,",current,"of",total)
            case "couponRedeemed":
                print("couponRedeemed triggered")
            case "EnableSyncing":
                print("EnableSyncing triggered")
            case "DisableSyncing":
                print("DisableSyncing triggered")
            case "consultationBooked":
                print("consultationBooked triggered")
            case "visitCallback":
                print("visitCallback triggered,", message, reason)
            case "NetworkError":
                print("NetworkError triggered,", message, code)
                
            case "ClosePWAEvent":
                // show initial button again, in actual app this can be ignored
                self.showButton();
                self.dismiss(animated: true)

            default:
                print("nothing")
        }
        print("method Received Notification",event)
    }
    
    @objc func buttonTapped(sender : UIButton) {
        // since both UIs share same view the button needs to be hidden, in actual app this can be ignored
        self.hideButton()
        
        // OPTIONAL : syncing is enabled by default but it can be toggled using this method
        visitHealthView.setSyncingEnabled(true)
        
        // modal implementation
        self.present(vc, animated: true)
        
        visitHealthView.loadVisitWebUrl("--magic-link--")
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

作者

81799742, [email protected]

许可证

VisitHealthSDK可在MIT许可证下获得。有关更多信息,请查看LICENSE文件。