123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- //
- // 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"];
- }
-
- [self notifyAddPlayers:userInfo];
-
- } else {
- [OneSignal sendTag:@"SufixUid" value:@"-"];
- }
-
- //设置测试推送标签
- [self setTestPushTag];
- }
- //设置测试推送标签
- - (void)setTestPushTag {
- #if DEBUG
- [OneSignal sendTag:@"TestUser" value:@"true"];
- #endif
- }
- //添加用户 (登录成功后调用)
- - (void)notifyAddPlayers:(ASUserModel *)model {
-
- NSString *token = [DataUtil loginToken];
- // token = [token stringByReplacingOccurrencesOfString:@"Bearer " withString:@""];
- NSDictionary *param = @{@"user_id":model.Id,
- @"email":model.email,
- @"group_id":model.group_id,
- @"store_id":@"1",
- @"token":token};
-
- UIViewController *topVC = topViewController();
- [[ASNetTools shared] postMsgWithPath:MsgAddPlayersUrl param:param success:^(id _Nonnull json) {
- // [MBProgressHUD hideHUDForView:topVC.view animated:YES];
- } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
- // [MBProgressHUD hideHUDForView:topVC.view animated:YES];
- [topVC.view makeToast:ReqNetWorkFaild duration:2 position:CSToastPositionCenter];
- }];
- }
- @end
|