123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- //
- // ZYLService.m
- // HeiHuaBaiHua
- //
- // Created by HeiHuaBaiHua on 16/6/2.
- // Copyright © 2016年 HeiHuaBaiHua. All rights reserved.
- //
- #import "ZYLService.h"
- @interface ZYLService ()
- @property (assign, nonatomic) ZYLServiceEnvironment environment;
- @end
- @implementation ZYLService
- #pragma mark - Interface
- static ZYLService *currentService;
- static dispatch_semaphore_t lock;
- + (ZYLService *)currentService {
-
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
-
- lock = dispatch_semaphore_create(1);
- currentService = [ZYLService environmentWithType:BuildServiceEnvironment];
- });
-
-
- return currentService;
- }
- + (void)switchToEnvironment:(ZYLServiceEnvironment)environment {
- dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER);
- NSString *environmentString = @"";
- switch (environment) {
- case ZYLServiceEnvironmentTest:
- environmentString = @"ZYLServiceEnvironmentTest";
- break;
- case ZYLServiceEnvironmentDevelop:
- environmentString = @"ZYLServiceEnvironmentDevelop";
- break;
- case ZYLServiceEnvironmentRelease:
- environmentString = @"ZYLServiceEnvironmentRelease";
- break;
- case ZYLServiceEnvironmentTestGy:
- environmentString = @"ZYLServiceEnvironmentTestGy";
- break;
- }
- [[NSUserDefaults standardUserDefaults] setObject:environmentString forKey:@"ZYLServiceEnvironment"];
- [[NSUserDefaults standardUserDefaults] synchronize];
- currentService = [ZYLService environmentWithType:environment];
- dispatch_semaphore_signal(lock);
- }
- + (ZYLService *)environmentWithType:(ZYLServiceEnvironment)environment {
-
- ZYLService *service = [ZYLService new];
- NSString *environmentString = [[NSUserDefaults standardUserDefaults] objectForKey:@"ZYLServiceEnvironment"];
- if ([BaseMethod isNOTNull:environmentString]) {
- if ([environmentString isEqualToString:@"ZYLServiceEnvironmentTest"]) {
- service.environment = ZYLServiceEnvironmentTest;
- }else if ([environmentString isEqualToString:@"ZYLServiceEnvironmentDevelop"]) {
- service.environment = ZYLServiceEnvironmentDevelop;
- }else if ([environmentString isEqualToString:@"ZYLServiceEnvironmentRelease"]) {
- service.environment = ZYLServiceEnvironmentRelease;
- }else if ([environmentString isEqualToString:@"ZYLServiceEnvironmentTestGy"]) {
- service.environment = ZYLServiceEnvironmentTestGy;
- }
- }else {
- service.environment = environment;
- }
- return service;
- }
- - (NSString *)baseUrl {
-
- switch (self.environment) {
- //case ZYLServiceEnvironmentTest: return @"http://api.timichat.net/";
- case ZYLServiceEnvironmentTest: return @"http:/47.98.212.223:9201/";
- case ZYLServiceEnvironmentDevelop: return @"http://api.rc.timichat.cn/";
- case ZYLServiceEnvironmentRelease: return @"https://api.timichat.cn/";
- case ZYLServiceEnvironmentTestGy: return @"http:/127.0.0.1:9201/";//http:/127.0.0.1:9201/、http:/192.168.3.13:9201/
- }
- }
- - (NSString *)mallBaseUrl {
-
- switch (self.environment) {
- //case ZYLServiceEnvironmentTest: return @"http://xkapi.laylib.com/";
- case ZYLServiceEnvironmentTest: return @"http:/47.98.212.223:9201/";
- case ZYLServiceEnvironmentDevelop: return @"http://xkapi.laylib.com/";
- case ZYLServiceEnvironmentRelease: return @"https://api.mfxike.com/";
- case ZYLServiceEnvironmentTestGy: return @"http:/127.0.0.1:9201/";//http:/127.0.0.1:9201/、http:/192.168.3.13:9201/
- }
- }
- @end
|