SwiftNetSwitch 0.3.2

SwiftNetSwitch 0.3.2

jackiehu 维护。



  • HU

Version Xcode 9.0+ iOS 11.0+ Swift 5.0+

如果你的 APP 在开发测试阶段需要多套网络环境,且不想频繁打包,可以使用这个组件很方便地在 APP 内切换各种配置好的网络环境。你需要找到一个页面用于添加组件入口:比如添加到导航栏上

        #if DEBUG
        //添加到导航栏上
        SwitchManager.shared.configWithNavBar(self) { type in
            print("完成设置,当前环境:\(type)")
        }
        
        //添加到导航栏上并且切换完成后杀死APP    
        SwitchManager.shared.configWithNavBar(self, true) { type in
            print("完成设置,当前环境:\(type)")
        }
        #endif

或者直接添加到页面内

        //添加到指定容器view里
        SwitchManager.shared.configWithView(self, vi) { type in
            print("\(type)")
        }
        
        //添加到指定容器view里,并且切换完成后杀死APP
        SwitchManager.shared.configWithView(self, vi, true) { type in
            print("\(type)")
        }
        
        //添加到VC上的指定位置
        SwitchManager.shared.configWithFrame(self, CGRect.init(x: 100, y: 100, width: 100, height: 50)) { type in
            print("完成")
        }

注意仅限 DEBUG 阶段使用。

环境变量设置:可以通过一个类来管理,也可以直接设置

class Config {
    static func setConfig(){
        SwitchManager.shared.defaultSign = .debug
        
        SwitchManager.shared.configHostDebug = ["DebugSever":"https://Debug.qq.com",
                                                "AppDebugSever":"https://Debug.baidu.com"]
        
        SwitchManager.shared.configHostRelease = ["ReleaseSever":"https://www.qq.com",
                                                  "AppReleaseSever":"https://www.baidu.com"]
        
        SwitchManager.shared.configHostDev = ["DevSever":"https://Dev.qq.com",
                                              "AppDevSever":"https://Dev.baidu.com"]
        
        SwitchManager.shared.configHostOther = ["OtherSever":"https://Other.qq.com",
                                                "AppOtherSever":"https://Other.baidu.com",
                                                "WebOtherSever":"https://Other.sina.com",
                                                "ShopOtherSever":"https://Other.taobao.com"]
        
        SwitchManager.shared.setDefaultNetworkConfig()
    }
}

环境变量,你可以创建一个私有的 pod 仓库,其中只有一个类用于设置环境变量,也是以 `configurations => ['Debug']` 的方式引入。

安装

Cocoapods

在 Podfile 中添加 pod 'SwiftNetSwitch', :configurations => ['Debug']。这样可以在上线打包时不带入测试环境代码,不建议使用其他引入方式。

更多砖块工具加速 APP 开发

ReadMe Card

ReadMe Card

ReadMe Card

ReadMe Card

ReadMe Card

ReadMe Card

ReadMe Card

ReadMe Card

ReadMe Card

ReadMe Card

ReadMe Card

ReadMe Card