ASPushOneSignalManager.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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:@"618fe580-bc97-4bf4-b2bb-5039f9dbbc82"];
  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. @end