ASPushOneSignalManager.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. } else {
  51. [OneSignal sendTag:@"SufixUid" value:@"-"];
  52. }
  53. //设置测试推送标签
  54. [self setTestPushTag];
  55. }
  56. //设置测试推送标签
  57. - (void)setTestPushTag {
  58. #if DEBUG
  59. [OneSignal sendTag:@"TestUser" value:@"true"];
  60. #endif
  61. }
  62. @end