NetworkConfig.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // NetworkConfig.h
  3. // AICity
  4. //
  5. // Created by API Versioning Implementation on 2025/10/10.
  6. // Copyright © 2025 TogetherWatch. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. /**
  10. * API版本配置
  11. *
  12. * 定义API版本常量和版本化URL构建逻辑
  13. */
  14. // API版本号
  15. #define API_VERSION @"v1"
  16. // 基础URL(根据编译配置区分Debug和Release)
  17. #ifdef DEBUG
  18. #ifndef BASE_API_URL
  19. // 自动区分模拟器和真机
  20. #if TARGET_IPHONE_SIMULATOR
  21. #define BASE_API_URL @"http://localhost:8888/"
  22. #else
  23. #define BASE_API_URL @"http://192.168.110.66:8888/"
  24. #endif
  25. #endif
  26. #else
  27. #ifndef BASE_API_URL
  28. #define BASE_API_URL @"https://backend.jsnoopyay.com/"
  29. #endif
  30. #endif
  31. // 版本化基础URL宏
  32. #define VERSIONED_BASE_URL [NSString stringWithFormat:@"%@api/%@/", BASE_API_URL, API_VERSION]
  33. /**
  34. * 网络配置类
  35. *
  36. * 提供API版本管理的工具方法
  37. */
  38. @interface NetworkConfig : NSObject
  39. /**
  40. * 获取版本化的基础URL
  41. *
  42. * @return 包含API版本前缀的完整基础URL
  43. *
  44. * 示例:
  45. * - Debug: http://192.168.110.66:8888/api/v1/
  46. * - Release: https://backend.jsnoopyay.com/api/v1/
  47. */
  48. + (NSString *)versionedBaseURL;
  49. /**
  50. * 获取当前API版本
  51. *
  52. * @return 版本标识符(如"v1")
  53. */
  54. + (NSString *)currentAPIVersion;
  55. /**
  56. * 获取原始基础URL(不含版本前缀)
  57. *
  58. * @return 基础URL
  59. */
  60. + (NSString *)baseURL;
  61. /**
  62. * 检查是否启用了API版本化
  63. *
  64. * @return YES表示启用版本化
  65. */
  66. + (BOOL)isVersioningEnabled;
  67. @end