// // Utils.m // GtSdkDemo // // Created by ak on 2020/03/20. // Copyright © 2019 Gexin Interactive (Beijing) Network Technology Co.,LTD. All rights reserved. // #import "Utils.h" #import @implementation Utils + (BOOL)PushModel { return [[NSUserDefaults standardUserDefaults] boolForKey:@"OffPushMode"]; } + (void)SetPushModel:(BOOL)mode { [[NSUserDefaults standardUserDefaults] setBool:mode forKey:@"OffPushMode"]; [[NSUserDefaults standardUserDefaults] synchronize]; } + (NSString *)getHexStringForData:(NSData *)data { NSUInteger len = [data length]; char *chars = (char *) [data bytes]; NSMutableString *hexString = [[NSMutableString alloc] init]; for (NSUInteger i = 0; i < len; i++) { [hexString appendString:[NSString stringWithFormat:@"%0.2hhx", chars[i]]]; } return hexString; } /// 时间转字符串 + (NSString *)formateTime:(NSDate *)date { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"HH:mm:ss"]; NSString *dateTime = [formatter stringFromDate:date]; return dateTime; } + (void)pushLocalNotification:(NSString *)title userInfo:(NSDictionary *)userInfo { NSData *jsonData = [title dataUsingEncoding:NSUTF8StringEncoding]; NSError *error; NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error]; if (error){ //NSLog(@"json格式string解析失败:%@",error); return ; } UNMutableNotificationContent *content = [UNMutableNotificationContent new]; content.title = dict[@"title"]; content.body = dict[@"content"]; content.userInfo = userInfo; UNNotificationRequest *req = [UNNotificationRequest requestWithIdentifier:@"id1" content:content trigger:nil]; [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:req withCompletionHandler:^(NSError * _Nullable error) { NSLog(@"addNotificationRequest added"); }]; } @end