美文网首页学习封装的demo材料常用方法iOS Developer
SYNetworkEnvironmentL:APP开发中网络环境

SYNetworkEnvironmentL:APP开发中网络环境

作者: 番薯大佬 | 来源:发表于2017-06-12 14:13 被阅读56次

    SYNetworkEnvironment

    使用效果图使用效果图 使用配置图1使用配置图1
    使用配置图2使用配置图2

    代码示例:

    // 导入头文件
    #import "SYNetworkEnvironment.h"
    
    // 初始化网络环境,即在方法"- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{}"中进行初始化。
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Override point for customization after application launch.
    
        // 标题按钮设置
        NetworkRequestEnvironment.titleFont = [UIFont systemFontOfSize:13.0];
        NetworkRequestEnvironment.titleColorNormal = [UIColor blackColor];
        NetworkRequestEnvironment.titleColorHlight = [UIColor redColor];
        // 环境设置
        NetworkRequestEnvironment.networkEnviroment = 0;
        NetworkRequestEnvironment.networkServiceDebug = @"http://www.hao123.com";
        NetworkRequestEnvironment.networkServiceRelease = @"http://www.baidu.com";
        NetworkRequestEnvironment.networkServiceDebugDict = @{@"天猫":@"http://www.tiaomiao.com",@"淘宝":@"http://www.taobao.com",@"京东":@"http://www.jindong.com"};
        // 初始化
        [NetworkRequestEnvironment initializeNetworkEnvironment];
    
        return YES;
    }
    
    // 添加到视图控制器,便于显示交互视图。如果网络环境的keyNetworkEnvironment值为1,则在对应视图控制器的导航栏右按钮位置显示交互按钮;如果值为0,则不显示,但可以在对应视图控制器的导航栏右按钮位置通过连续点击5次显示交互选择视图。
    // 退出,或不退出APP
    [NetworkRequestEnvironment networkButtonWithNavigation:self exitApp:NO complete:^{
        // UIWindow *window = [[UIApplication sharedApplication].delegate window];
        // window.rootViewController = [UIApplication sharedApplication].delegate
    
        AppDelegate *appDelegate = ((AppDelegate *)[UIApplication sharedApplication].delegate);
        [appDelegate initRootViewController];
    }];
    
    // 添加到指定视图的指定位置
    [NetworkRequestEnvironment networkButtonWithView:self.view frame:CGRectMake(10.0, 200.0, 100.0, 40.0) exitApp:NO complete:^{
    
    }];
    
    // 获取定义的网络环境,如:
    NSString *url = NetworkRequestHost;
    NSLog(@"url = %@", url);
    

    相关文章

      网友评论

        本文标题:SYNetworkEnvironmentL:APP开发中网络环境

        本文链接:https://www.haomeiwen.com/subject/wgelqxtx.html