1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- //
- // ASPushOneSignalManager.m
- // Asteria
- //
- // Created by xingyu on 2024/7/11.
- //
- #import "ASPushOneSignalManager.h"
- #import <OneSignal/OneSignal.h>
- @interface ASPushOneSignalManager()<UNUserNotificationCenterDelegate>
- @end
- @implementation ASPushOneSignalManager
- + (instancetype)shared {
- static id sharedInstance = nil;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- sharedInstance = [[self alloc] init];
- });
- return sharedInstance;
- }
- - (void)initOneSignalSDKWithPushConfig:(NSDictionary *)launchOptions {
-
- [OneSignal setLogLevel:ONE_S_LL_VERBOSE visualLevel:ONE_S_LL_NONE];
-
- // OneSignal initialization
- [OneSignal initWithLaunchOptions:launchOptions];
- [OneSignal setAppId:OneSignalAppId];
- // promptForPushNotifications will show the native iOS notification permission prompt.
- // We recommend removing the following code and instead using an In-App Message to prompt for notification permission (See step 8)
- [OneSignal promptForPushNotificationsWithUserResponse:^(BOOL accepted) {
- NSLog(@"User accepted notifications: %d", accepted);
- }];
-
- }
- #pragma mark ---- 设置用户推送标签 ----
- - (void)setPushApnsTagWithUserInfo {
-
- if ([ASUserInfoManager shared].isLogin) {
- ASUserModel *userInfo = [[ASUserInfoManager shared] userInfo];
- if (!userInfo.Id.isEmpty) {
- NSInteger sufix = userInfo.Id.integerValue%10;
- [OneSignal sendTag:@"SufixUid" value:[NSString stringWithFormat:@"%ld", sufix]];
- }
- if (userInfo.group_id.intValue == 5) {
- [OneSignal sendTag:@"IsOrdered" value:@"true"];
- #if (DEBUG)
- [OneSignal sendTag:@"testOrderd" value:@"true"];
- #endif
- } else {
- #if (DEBUG)
- [OneSignal deleteTag:@"testOrderd"];
- #endif
- [OneSignal deleteTag:@"IsOrdered"];
- }
-
- } else {
- [OneSignal sendTag:@"SufixUid" value:@"-"];
- }
-
- //设置测试推送标签
- [self setTestPushTag];
- }
- //设置测试推送标签
- - (void)setTestPushTag {
- #if DEBUG
- [OneSignal sendTag:@"TestUser" value:@"true"];
- #endif
- }
- @end
|