| 
              //
//  AppDelegate.swift
//  PaiAi
//
//  Created by zhengjianfei on 16/3/28.
//  Copyright © 2016年 FFIB. All rights reserved.
//
import UIKit
import Paiai_iOS
import PaiaiUIKit
import PaiaiDataKit
let WXPayDidFinishNotification = "WXPayDidFinishNotification"
let WXPayErrorCode = "WXPayErrorCode"
let WXPayErrorStr = "WXPayErrorStr"
let WXAppid = "wx4e22a0c8ae6d766d"
let WXSecret = "636ac848016c593575d11143c55c8333"
private let QQAppid = "1105111674"
private let QQSecret = "OFQ2J1RBMJyHPW8G"
private let WBAppid = "2730190333"
private let WBSecret = "ff16591583c7bcf4a0d781eae316635a"
private let WIFIUploadOriginal = "WIFIUploadOriginal"
private let ReceivePush = "ReceivePush"
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, WXApiDelegate {
    var window: UIWindow?
    var coordinator: AppCoordinator?
    
    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?)
        -> Bool {
            registerAppConfiguration()
            let rootViewController = ContainerViewController()
            let nav = UINavigationController(rootViewController: rootViewController)
            
            window = UIWindow(frame: UIScreen.main.bounds)
            window?.rootViewController = nav
            window?.makeKeyAndVisible()
            
            coordinator = AppCoordinator(rootViewController, navigationController: nav)
            
            nav.navigationBar.tintColor = UIColor.white
            nav.navigationBar.isTranslucent = false
            nav.navigationBar.setBackgroundImage(UIImage.Navigation.background, for: .default)
            nav.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white.cgColor]
            return true
    }
    func application(_ app: UIApplication, open url: URL,
                     options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool {
        var result: Bool = false
        #if !((arch(i386) || arch(x86_64)))
            switch sharedPlatform {
            case 0:
                result =  WXApi.handleOpen(url, delegate: self)
            case 1:
                result = TencentOAuth.handleOpen(url)
            case 2:
                result = WeiboSDK.handleOpen(url, delegate: nil)
            default:
                assert(false, "\((#file as NSString).lastPathComponent)[\(#line)], \(#function): share error")
            }
        #endif
        return result
    }
    func application(_ application: UIApplication, open url: URL,
                     sourceApplication: String?, annotation: Any) -> Bool {
        var result: Bool = false
        #if !((arch(i386) || arch(x86_64)))
            switch sharedPlatform {
            case 0:
                result =  WXApi.handleOpen(url, delegate: self)
            case 1:
                result = TencentOAuth.handleOpen(url)
            case 2:
                result = WeiboSDK.handleOpen(url, delegate: nil)
            default:
                assert(false, "\((#file as NSString).lastPathComponent)[\(#line)], \(#function): share error")
            }
        #endif
        return result
    }
    #if !((arch(i386) || arch(x86_64)))
    func onResp(_ resp: BaseResp!) {
        if let resp = resp as? PayResp {
            var userInfo: [String: AnyObject] = [(WXPayErrorCode as NSObject) as! String: Int(resp.errCode) as AnyObject]
            if resp.errStr != nil {
                userInfo[WXPayErrorStr] = resp.errStr as AnyObject?
            }
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: WXPayDidFinishNotification), object: nil, userInfo: userInfo)
        } else if let resp = resp as? SendAuthResp, let code = resp.code {
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: WXPayDidFinishNotification), object: nil, userInfo: userInfo)
            wxLoginJumpFinishCallback?(["code": code as AnyObject], nil)
            wxLoginJumpFinishCallback = nil
        }
    }
    #endif
}
extension AppDelegate {
    func registerAppConfiguration() {
        WXApi.registerApp(WXAppid)
//        _ = TencentOAuth(appId: QQAppid, andDelegate: nil)
//        WeiboSDK.registerApp(WBAppid)
//        let analyticsConfig = UMAnalyticsConfig.sharedInstance()
//        analyticsConfig?.appKey = "58c5ebcdae1bf82bc9001ff9"
//        analyticsConfig?.channelId = "App Store"
//        MobClick.start(withConfigure: analyticsConfig)
        UserDefaults.standard.register(defaults: [
            WIFIUploadOriginal: true,
            ReceivePush: true
        ])
    }
}
 
  |