ASPushOneSignalManager.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // ASPushOneSignalManager.m
  3. // Asteria
  4. //
  5. // Created by xingyu on 2024/7/11.
  6. //
  7. #import "ASPushOneSignalManager.h"
  8. #import <OneSignal/OneSignal.h>
  9. @interface ASPushOneSignalManager()<UNUserNotificationCenterDelegate>
  10. @end
  11. @implementation ASPushOneSignalManager
  12. + (instancetype)shared {
  13. static id sharedInstance = nil;
  14. static dispatch_once_t onceToken;
  15. dispatch_once(&onceToken, ^{
  16. sharedInstance = [[self alloc] init];
  17. });
  18. return sharedInstance;
  19. }
  20. - (void)initOneSignalSDKWithPushConfig:(NSDictionary *)launchOptions {
  21. [OneSignal setLogLevel:ONE_S_LL_VERBOSE visualLevel:ONE_S_LL_NONE];
  22. // OneSignal initialization
  23. [OneSignal initWithLaunchOptions:launchOptions];
  24. [OneSignal setAppId:OneSignalAppId];
  25. // promptForPushNotifications will show the native iOS notification permission prompt.
  26. // We recommend removing the following code and instead using an In-App Message to prompt for notification permission (See step 8)
  27. [OneSignal promptForPushNotificationsWithUserResponse:^(BOOL accepted) {
  28. NSLog(@"User accepted notifications: %d", accepted);
  29. }];
  30. }
  31. #pragma mark ---- 设置用户推送标签 ----
  32. - (void)setPushApnsTagWithUserInfo {
  33. if ([ASUserInfoManager shared].isLogin) {
  34. ASUserModel *userInfo = [[ASUserInfoManager shared] userInfo];
  35. if (!userInfo.Id.isEmpty) {
  36. NSInteger sufix = userInfo.Id.integerValue%10;
  37. [OneSignal sendTag:@"SufixUid" value:[NSString stringWithFormat:@"%ld", sufix]];
  38. }
  39. if (userInfo.group_id.intValue == 5) {
  40. [OneSignal sendTag:@"IsOrdered" value:@"true"];
  41. #if (DEBUG)
  42. [OneSignal sendTag:@"testOrderd" value:@"true"];
  43. #endif
  44. } else {
  45. #if (DEBUG)
  46. [OneSignal deleteTag:@"testOrderd"];
  47. #endif
  48. [OneSignal deleteTag:@"IsOrdered"];
  49. }
  50. [self notifyAddPlayers:userInfo];
  51. } else {
  52. [OneSignal sendTag:@"SufixUid" value:@"-"];
  53. }
  54. //设置测试推送标签
  55. [self setTestPushTag];
  56. }
  57. //设置测试推送标签
  58. - (void)setTestPushTag {
  59. #if DEBUG
  60. [OneSignal sendTag:@"TestUser" value:@"true"];
  61. #endif
  62. }
  63. //添加用户 (登录成功后调用)
  64. - (void)notifyAddPlayers:(ASUserModel *)model {
  65. NSString *token = [DataUtil loginToken];
  66. // token = [token stringByReplacingOccurrencesOfString:@"Bearer " withString:@""];
  67. NSDictionary *param = @{@"user_id":model.Id,
  68. @"email":model.email,
  69. @"group_id":model.group_id,
  70. @"store_id":@"1",
  71. @"token":token};
  72. UIViewController *topVC = topViewController();
  73. [[ASNetTools shared] postMsgWithPath:MsgAddPlayersUrl param:param success:^(id _Nonnull json) {
  74. // [MBProgressHUD hideHUDForView:topVC.view animated:YES];
  75. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  76. // [MBProgressHUD hideHUDForView:topVC.view animated:YES];
  77. [topVC.view makeToast:ReqNetWorkFaild duration:2 position:CSToastPositionCenter];
  78. }];
  79. }
  80. @end