123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662 |
- import UIKit
- var navheight = CGFloat(0)
- @UIApplicationMain
- @objcMembers
- class AppDelegate: UIResponder, UIApplicationDelegate, JPUSHRegisterDelegate, WXApiDelegate, UITabBarControllerDelegate {
-
- var window: UIWindow?
- let openMerchants = OpeningMerchantsQybRequestEntity()
- let arrIcon = ["ion_tab_01", "ion_tab_02", "ion_tab_wallet", "ion_tab_04"]
-
- var rongYunAppkey = "";
-
- let wxAppKey = "wxa6b6403ce27573d1"
-
- var umAppKey = "5cb15084570df3a22f001381";
-
- var jpushAppKey = "9f1d705c47d3893d5e31aae4"
- var dicDefault = NSMutableDictionary()
- var mainTabbar: CustomTabBarController!
- var navController: MainNavigationController!
- func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
-
- if CommonValue.getDefaultUserInfoForString(key: "common_default_is_ss_password") == "" || CommonValue.getUserId() == "" {
- CommonValue.setDefaultUserInfoForString(value: "0", key: "common_default_is_ss_password")
- }
- window = UIWindow(frame: UIScreen.main.bounds)
- initCusService()
-
- let config = BuglyConfig()
- config.channel = "AppStore"
-
- Bugly.start(withAppId: "eac41aea64", config: config)
-
-
- if ScreenHeight < ScreenWidth {
- ScreenWidth = UIScreen.main.bounds.size.height
- ScreenHeight = UIScreen.main.bounds.size.width
- }
-
- let searchPaths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
- print(searchPaths)
- UIApplication.shared.setStatusBarStyle(.lightContent, animated: false)
- mainTabbar = CustomTabBarController()
-
-
- navController = MainNavigationController(rootViewController: mainTabbar)
-
-
-
- navController.navigationBar.isTranslucent = false
- navController.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: ThemeManager.sharedInstance().getNavTitleColor()]
- GB_Nav = navController
- IQKeyboardManager.shared.enable = true
- var navImageName = "img_nav_common"
- if isIphoneX {
- navImageName = "img_nav_common_x"
- }
- navController.navigationBar.setBackgroundImage(UIImage(named: navImageName), for: .default)
- navController.navigationBar.alpha = 1
- window?.rootViewController = navController
-
- if !CommonUntils.getIsSimulator() {
- WXApi.registerApp(wxAppKey)
- }
-
- if !CommonUntils.getIsSimulator() {
- initUMInfo()
-
- regusterJPush(launchOptions: launchOptions)
- }
- window?.makeKeyAndVisible()
- if !GlobalMethod.isLoginSuccess(){
- let vcvc = LoginViewController()
- GB_Nav.pushViewController(vcvc, animated: true)
- }
- initSystem()
-
- if ScreenHeight == 812 {
- navheight = 88
- } else {
- navheight = 64
- }
- UIApplication.shared.applicationIconBadgeNumber = 0
- return true
- }
-
- func initCusService() {
- QYSDK.shared().registerAppId("de75afb7b0a388e038e03e6eb51d73d0", appName: "星创客")
- }
- func initCusServiceUserInfo() {
- let userInfo = QYUserInfo()
- userInfo.userId = CommonValue.getUserId()
- let dicName = ["key": "real_name", "value": CommonValue.getUserNickName()]
- let dicPhone = ["key": "mobile_phone", "value": CommonValue.getUserPhone()]
- let dicCode = ["key": "bankcard", "value": CommonValue.getUserRecCode(), "index": "0", "label": "推荐码"]
- let array = NSMutableArray(array: [dicName, dicPhone, dicCode])
- userInfo.data = CommonJSON.arrayToJson(arr: array)
- QYSDK.shared()?.setUserInfo(userInfo, authTokenVerificationResultBlock: { (succ) in
- print("====\(succ)===")
- })
- }
- let menu1 = HomeViewController()
-
- func initTabbarController() {
- let menu2 = BusinessMainViewController()
- let menu3 = WalletMainViewController()
- let menu4 = MyViewController()
- menu1.tabBarItem.tag = 1001
- menu1.tabBarItem.image = UIImage.init(named: "")
- menu1.title = "首页"
- menu2.tabBarItem.tag = 1002
- menu2.tabBarItem.image = UIImage.init(named: "")
- menu2.title = "业务"
- menu3.tabBarItem.tag = 1003
- menu3.tabBarItem.image = UIImage.init(named: "")
- menu3.title = "钱包"
- menu4.tabBarItem.tag = 1004
- menu4.tabBarItem.image = UIImage.init(named: "")
- menu4.title = "我的"
- mainTabbar.viewControllers = [menu1, menu2, menu3, menu4]
- let frame = CGRect(x: 0, y: 0, width: ScreenWidth, height: 49)
- let bottomView = UIView(frame: frame)
- bottomView.backgroundColor = UIColor.white
- mainTabbar.tabBar.insertSubview(bottomView, at: 0)
- mainTabbar.tabBar.isOpaque = true
- let items = mainTabbar.tabBar.items
- for i in 0...arrIcon.count-1 {
- if i >= items!.count {
- break
- }
- let item = items![i]
- item.image = UIImage(named: "\(arrIcon[i])_n")?.withRenderingMode(.alwaysOriginal)
- item.selectedImage = UIImage(named: "\(arrIcon[i])_s")?.withRenderingMode(.alwaysOriginal)
- item.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: ThemeManager.sharedInstance().getTabbarDefaultFontColor()], for: .normal)
- item.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: ThemeManager.sharedInstance().getTabbarSelectedFontColor()], for: .highlighted)
- }
- }
- func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
- if CommonValue.getUserId() == "" {
- appDelegate.navController.pushViewController(LoginViewController(), animated: true)
- return false
- }
- return true
- }
-
- func initUMInfo() {
- if umAppKey == "" {
- return
- }
- print("====初始化友盟====")
-
- UMSocialManager.default().openLog(true)
- UMSocialManager.default().umSocialAppkey = umAppKey
- UMSocialManager.default().setPlaform(.wechatSession, appKey: wxAppKey, appSecret: "", redirectURL: "http://mobile.umeng.com/social")
-
-
- }
-
- func regusterJPush(launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
- if jpushAppKey == "" {
- return
- }
- print("====初始化极光====")
- UIRemoteNotificationType.badge
- print(UIDevice.current.systemVersion)
-
- regJpush()
-
- JPUSHService.setup(withOption: launchOptions, appKey: jpushAppKey, channel: "Publish channel", apsForProduction: false)
- }
- func getValueForSystemVersion() -> Float {
- let str = UIDevice.current.systemVersion
- let strs = str.split(s: ".")
- if strs.count >= 1 {
- return Float(strs[0] + "." + strs[1])!
- } else {
- return Float(str)!
- }
- }
- var timer: Timer!
- var isBackgroudRun = false
-
- func regJpush() {
- if getValueForSystemVersion() >= Float(10.0) {
- let entity = JPUSHRegisterEntity()
- entity.types = Int(UIUserNotificationType.badge.rawValue) | Int(UIUserNotificationType.sound.rawValue) | Int(UIUserNotificationType.alert.rawValue)
- JPUSHService.register(forRemoteNotificationConfig: entity, delegate: self)
- } else if getValueForSystemVersion() >= Float(8.0) {
- regjpushtwo()
- } else {
- regjpushtwo()
- }
- }
- func regjpushtwo() {
- JPUSHService.register(forRemoteNotificationTypes: UIRemoteNotificationType.badge.rawValue | UIRemoteNotificationType.sound.rawValue, categories: nil)
- }
- @available(iOS 10.0, *)
- func jpushNotificationCenter(_ center: UNUserNotificationCenter!, willPresent notification: UNNotification!, withCompletionHandler completionHandler: ((Int) -> Void)!) {
- let userIf = notification.request.content.userInfo
- print("-----收到推送处理11111 运行中")
- completionHandler(Int(UNAuthorizationOptions.badge.rawValue))
- jPushinfo(userInfo: userIf as NSDictionary)
- completionHandler
- }
- @available(iOS 10.0, *)
- func jpushNotificationCenter(_ center: UNUserNotificationCenter!, didReceive response: UNNotificationResponse!, withCompletionHandler completionHandler: (() -> Void)!) {
- let userIf = response.notification.request.content.userInfo
- print("-----收到推送处理22222 后台")
- jPushinfo(userInfo: userIf as NSDictionary)
- completionHandler
- }
- func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
- JPUSHService.registerDeviceToken(deviceToken)
- }
- func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
- JPUSHService.handleRemoteNotification(userInfo)
- }
- func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
- print("-----收到推送处理3333---=IOS 10以下自己判断前后台=")
- jPushinfo(userInfo: userInfo as NSDictionary)
- }
- func jPushinfo(userInfo: NSDictionary) {
- print("-----收到推送处理\n")
- print(userInfo)
- if userInfo["messageId"] as? String == nil {
- return
- } else {
- var strTitle = ""
- let dicAPS = userInfo["aps"] as? NSDictionary
- if dicAPS != nil {
- strTitle = dicAPS!.getString(key: "alert")
- }
- if isBackgroudRun {
- let view = CommonWebViewViewController()
- view.strTitle = strTitle
- view.url = "http://106.xingchuangke.net:8889/phoneMobile/messageWeb?id=\(userInfo["messageId"] as! String)"
- navController.pushViewController(view, animated: true)
- } else {
- CommonUntils.AlertView(controller: navController, title: "提示", message: "收到系统消息,是否立即查看?", buttons: ["立即查看"], style: .alert) {[weak self] (_, _) in
- let view = CommonWebViewViewController()
- view.strTitle = strTitle
- view.url = "http://106.xingchuangke.net:8889/phoneMobile/messageWeb?id=\(userInfo["messageId"] as! String)"
- self!.navController.pushViewController(view, animated: true)
- }
- }
- }
- }
- @objc func timerAction() {
- isBackgroudRun = false
- }
- func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
- _ = UMSocialManager.default().handleOpen(url)
- return true
- }
- func applicationWillResignActive(_ application: UIApplication) {
-
-
- }
- func applicationDidEnterBackground(_ application: UIApplication) {
- isBackgroudRun = true
- print("====go Background===")
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "defulat_notification_go_backgroud"), object: nil, userInfo: nil)
-
-
- }
- func applicationWillEnterForeground(_ application: UIApplication) {
- reloadUserInfo()
- print("====go Foreground===")
- UIApplication.shared.applicationIconBadgeNumber = 0
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "defulat_notification_go_foreground"), object: nil, userInfo: nil)
-
- }
- func applicationDidBecomeActive(_ application: UIApplication) {
- self.perform(#selector(AppDelegate.timerAction), with: nil, afterDelay: 2)
- print("====go BecomeActive===")
- if CommonValue.getIsValitePassword() {
- let guest = GuesturePasswordViewController()
- guest.type = 1
- appDelegate.navController.pushViewController(guest, animated: true)
- }
-
- }
- func applicationWillTerminate(_ application: UIApplication) {
-
- }
- var viewGuangGao: UIView!
- var imgGuangGao: UIImageView!
- var lblCloseTime: UILabel!
- var dicImageInfo: NSDictionary!
-
- func loadGuangGao() {
- viewGuangGao = UIView(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: ScreenHeight))
-
- if ScreenHeight <= 480 {
- imgGuangGao = UIImageView(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: ScreenWidth * 1.16))
- } else {
- imgGuangGao = UIImageView(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: ScreenWidth * 1.4375))
- }
- viewGuangGao.addSubview(imgGuangGao)
-
- let imgView = UIImageView(frame: CGRect(x: 0, y: ScreenHeight - (ScreenWidth * 0.34), width: ScreenWidth, height: ScreenWidth * 0.34))
- imgView.image = UIImage(named: "ad_logo_860x294_@1x")
- viewGuangGao.addSubview(imgView)
- viewGuangGao.layer.zPosition = 9999999
- lblCloseTime = UILabel(frame: CGRect(x: ScreenWidth - 85, y: 30, width: 70, height: 30))
- lblCloseTime.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0x000000, alpha: 0.5)
- lblCloseTime.textColor = UIColor.white
- lblCloseTime.font = UIFont.systemFont(ofSize: 13)
- lblCloseTime.textAlignment = .center
- lblCloseTime.setCornerRadius(size: 4)
- lblCloseTime.isHidden = true
- viewGuangGao.addSubview(lblCloseTime)
- appDelegate.navController.view.addSubview(viewGuangGao)
-
- self.perform(#selector(autoHiddenGuangGao), with: nil, afterDelay: 6)
- }
- var isLoadGuangGao = false
- @objc func autoHiddenGuangGao() {
- if !isLoadGuangGao {
- hiddenGuangGao()
- }
- }
-
- func loadGuangGaoImage(dic: NSDictionary) {
- isLoadGuangGao = true
- var imgUrl = ""
- if CommonUntils.isIphonex() {
- if dic["imageSpe"] != nil {
- imgUrl = dic["imageSpe"] as! String
- }
- } else {
- if dic["image"] != nil {
- imgUrl = dic["image"] as! String
- }
- }
- if imgUrl == "" {
- hiddenGuangGao()
- } else {
- lblCloseTime.isHidden = false
- imgGuangGao.sd_setImage(with: URL(string: imgUrl)!) {[weak self] (img, _, _, _) in
- self!.imgGuangGao.setSizeWidth(width: ScreenWidth)
- self!.imgGuangGao.setSizeHeight(height: ScreenWidth / img!.size.width * img!.size.height)
- self!.timerAD = Timer.scheduledTimer(timeInterval: 1, target: self!, selector: #selector(self!.refreshTime), userInfo: nil, repeats: true)
- self!.timerAD.fireDate = Date.distantPast
- }
- let btn = UIButton(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: ScreenHeight))
- viewGuangGao.addSubview(btn)
- btn.addTarget(self, action: #selector(btnGuangGaoClick), for: .touchUpInside)
- lblCloseTime.text = "\(count)s跳过"
- }
- }
- var timerAD: Timer!
-
- @objc func btnGuangGaoClick() {
- count = 1
- hiddenGuangGao()
-
- }
- var count = 3
- @objc func refreshTime() {
- if count == 1 {
- if timerAD != nil {
- timerAD.fireDate = Date.distantFuture
- }
- hiddenGuangGao()
- return
- } else if count < 1 {
- if timerAD != nil {
- timerAD.fireDate = Date.distantFuture
- }
- hiddenGuangGao()
- return
- }
- count -= 1
- lblCloseTime.text = "\(count)s跳过"
- }
-
- var isHiddenGuangeGao = false
- func hiddenGuangGao() {
- if isHiddenGuangeGao {
- return
- }
- isHiddenGuangeGao = true
- if viewGuangGao != nil {
- UIView.animate(withDuration: 0.6, animations: {
- self.viewGuangGao.alpha = 0
- self.viewGuangGao.transform = CGAffineTransform(scaleX: 1.1, y: 1.1)
- }, completion: { (_) in
- self.viewGuangGao.isHidden = true
-
- })
- }
- }
- var isInitSysteming = false
- var initSystemIsSucces = false
-
- func initSystem() {
- if initSystemIsSucces || isInitSysteming {
- return
- }
- isInitSysteming = true
- let params = NSMutableDictionary()
- if CommonValue.getUserId() == "" {
- params.setValue("", forKey: "aid")
- } else {
- params.setValue(CommonValue.getUserId(), forKey: "aid")
- }
- let http = CommonValue.getHttp()
- let url = RequestURL.initProgram
- http.get(url, parameters: params, progress: nil, success: {[weak self] (_, json1) -> Void in
- self!.isInitSysteming = false
- self!.initSystemIsSucces = true
- let json = json1 as! NSDictionary
- if isPrintLog {
- print(json)
- }
- let succeed = json.object(forKey: "succeed") as! String
- if succeed == "000" {
- let dataInfo = json["dataInfo"] as? NSDictionary
- CommonValue.setDefaultUserInfoForObject(value: dataInfo!, key: "common_default_init_data")
- self!.dicDefault.setDictionary(dataInfo! as! [AnyHashable: Any])
- RequestURL.qiNiuImageUrl = dataInfo!["qnUrl"] as! String
-
-
- self!.upgradeSystem()
- self!.reloadUserInfo()
- if self!.menu1.headerView != nil {
- self!.menu1.headerView.initView()
- }
- if self!.menu1.tableView != nil {
- self!.menu1.tableView.reloadData()
- }
- }
- }, failure: {[weak self] (_, _) -> Void in
- self!.isInitSysteming = false
- self!.reloadUserInfo()
- let obj = CommonValue.getDefaultUserInfoForObject(key: "common_default_init_data")
- if obj != nil && (obj as? NSDictionary) != nil {
- self!.dicDefault.setDictionary((obj as! NSDictionary) as! [AnyHashable: Any])
- RequestURL.qiNiuImageUrl = self!.dicDefault["qnUrl"] as! String
-
-
- } else {
- self!.hiddenGuangGao()
- }
- })
- }
- func upgradeSystem() {
- if UserDefault.object(forKey: launchView) == nil {
- return
- }
- if dicDefault["apkVersion"] as? NSDictionary != nil {
- let dicApkVersion = dicDefault["apkVersion"] as! NSDictionary
- if CommonUntils.getSystemVersion() != dicApkVersion.getString(key: "apkversion") {
- if CommonUntils.checkVersionIsUpload(serverVersion: dicApkVersion.getString(key: "apkversion")) {
- let viewAlert = CommonViewUntils.getViewForXIB(xibName: "UpdateAlertView") as! UpdateAlertView
- viewAlert.initView(alert: dicApkVersion.getString(key: "detail"), upgradeUrl: dicApkVersion.getString(key: "apkurl"))
- appDelegate.navController.showBackgroudView(viewContent: viewAlert, isCenter: true, clickOtherIsClose: false)
- return
- }
- }
- }
- }
-
- func reloadUserInfo() {
- if CommonValue.getUserId() == "" {
- return
- }
- let params = NSMutableDictionary()
- let http = CommonValue.getHttp()
- params.setValue(CommonValue.getUserId(), forKey: "userId")
- let url = RequestURL.findUserById
- http.get(url, parameters: params, progress: nil, success: {[weak self] (_, json1) -> Void in
- print(json1)
- let json = json1 as! NSDictionary
- let succeed = json.object(forKey: "succeed") as! String
- self!.initCusServiceUserInfo()
- if succeed == "000" {
- let dataInfo = json["dataInfo"] as? NSDictionary
- if dataInfo != nil {
- CommonValue.setLoginUserInfo(loginUser: NSMutableDictionary(dictionary: dataInfo!))
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "noti_reload_user"), object: nil, userInfo: nil)
-
- }
- }
- }, failure: { (_, _) -> Void in
- })
- }
-
- func getAddressSavePlist() {
- let params = NSMutableDictionary()
- let http = AFHTTPSessionManager()
- http.requestSerializer.setValue(CommonValue.getUserId(), forHTTPHeaderField: "userId")
- http.requestSerializer.setValue("1", forHTTPHeaderField: "phoneType")
- http.requestSerializer.setValue(CommonUntils.getSystemVersion(), forHTTPHeaderField: "apkVersion")
- params.setValue(CommonValue.getUserId(), forKey: "userId")
- let url = RequestURL.getProvincesOrCity
- http.get(url, parameters: params, progress: nil, success: { (_, json1) -> Void in
- let json = json1 as! NSDictionary
- let succeed = json.object(forKey: "succeed") as! String
- if succeed == "000" {
- let dataInfo = json["dataInfo"] as? NSArray
- if dataInfo != nil {
- dataInfo!.write(toFile: "\(CommonUntils.getAppPath())address1111.plist", atomically: true)
- print(CommonUntils.getAppPath())
- print("====保存成功=")
- }
- }
- }, failure: { (_, _) -> Void in
- })
- }
-
- override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
- for touch: AnyObject in touches {
- let t = touch as! UITouch
- if t.location(in: nil).y > 20 {
- return
- }
- }
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "commo_stateBarClick"), object: nil)
- }
-
- func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
- if url.host!.has(s: "safepay") {
- AlipaySDK.defaultService().processOrder(withPaymentResult: url, standbyCallback: { (content) in
- let nc = NotificationCenter.default
- nc.post(name: NSNotification.Name(rawValue: "notification_alipay"), object: String((content as! NSDictionary)["resultStatus"] as! String))
- })
- }
- UMSocialManager.default().handleOpen(url)
- WXApi.handleOpen(url, delegate: self)
- return true
- }
- func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
- if url.host!.has(s: "safepay") {
- AlipaySDK.defaultService().processOrder(withPaymentResult: url, standbyCallback: { (content) in
- let nc = NotificationCenter.default
- nc.post(name: NSNotification.Name(rawValue: "notification_alipay"), object: String((content as! NSDictionary)["resultStatus"] as! String))
- })
- }
- UMSocialManager.default().handleOpen(url)
- WXApi.handleOpen(url, delegate: self)
- return true
- }
-
- func onResp(_ resp: BaseResp) {
- print("微信回调\n\(resp.type)")
- print("微信回调\n\(resp.errCode)")
- print("微信回调\n\(resp.errStr)")
- let nc = NotificationCenter.default
- nc.post(name: NSNotification.Name(rawValue: "notification_weixinpay"), object: String(resp.errCode))
- }
- func setNavigationBarHidden(isHidden: Bool) {
- if navController != nil {
- navController.setNavigationBarHidden(isHidden, animated: false)
- }
- }
- }
|