platforms.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package model
  2. import "strings"
  3. // PushSDK* for parameter 'push_sdk' in http report API.
  4. const (
  5. // PushSDKApns apns sdk.
  6. PushSDKApns = 1
  7. // PushSDKXiaomi mipush sdk.
  8. PushSDKXiaomi = 2
  9. // PushSDKHuawei huawei sdk.
  10. PushSDKHuawei = 3
  11. // PushSDKOppo oppo sdk.
  12. PushSDKOppo = 5
  13. // PushSDKJpush jpush sdk.
  14. PushSDKJpush = 6
  15. // PushSDKFCM fcm sdk
  16. PushSDKFCM = 7
  17. )
  18. const (
  19. // PlatformUnknown unknown.
  20. PlatformUnknown = 0
  21. // PlatformAndroid Android.
  22. PlatformAndroid = 1
  23. // PlatformIPhone iPhone.
  24. PlatformIPhone = 2
  25. // PlatformIPad iPad.
  26. PlatformIPad = 3
  27. // PlatformXiaomi mipush.
  28. PlatformXiaomi = 4
  29. // PlatformHuawei huawei.
  30. PlatformHuawei = 5
  31. // PlatformOppo oppo.
  32. PlatformOppo = 8
  33. // PlatformJpush jpush.
  34. PlatformJpush = 9
  35. // PlatformFCM fcm
  36. PlatformFCM = 10
  37. )
  38. // Platforms all platform
  39. var Platforms = []int{
  40. PlatformIPhone,
  41. PlatformIPad,
  42. PlatformXiaomi,
  43. PlatformHuawei,
  44. PlatformOppo,
  45. PlatformJpush,
  46. PlatformFCM,
  47. }
  48. // Platform gets real platform.
  49. func Platform(platform string, pushSDK int) int {
  50. switch pushSDK {
  51. case PushSDKApns:
  52. platform = strings.ToLower(platform)
  53. if strings.HasPrefix(platform, "iphone") {
  54. return PlatformIPhone
  55. } else if strings.HasPrefix(platform, "ipad") {
  56. return PlatformIPad
  57. }
  58. case PushSDKXiaomi:
  59. return PlatformXiaomi
  60. case PushSDKHuawei:
  61. return PlatformHuawei
  62. case PushSDKOppo:
  63. return PlatformOppo
  64. case PushSDKJpush:
  65. return PlatformJpush
  66. case PushSDKFCM:
  67. return PlatformFCM
  68. }
  69. // TODO add more brands
  70. return PlatformUnknown
  71. }