This repository was archived by the owner on Feb 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppDelegate+oc.m
More file actions
47 lines (39 loc) · 1.92 KB
/
AppDelegate+oc.m
File metadata and controls
47 lines (39 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// AppDelegate+oc.m
// boxin
//
// Created by guduzhonglao on 10/17/19.
// Copyright © 2019 guduzhonglao. All rights reserved.
//
#import "AppDelegate+oc.h"
@implementation AppDelegate (oc)
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
if (@available(iOS 13.0, *)) {
dispatch_async(dispatch_queue_create("updateDeviceToken", NULL), ^{
const unsigned *tokenBytes = [deviceToken bytes];
NSString *token = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
NSMutableString *t = [NSMutableString string];
for (int i=0; i<8; i++) {
[t appendFormat:@"%02x", tokenBytes[i]];
}
[[NSUserDefaults standardUserDefaults] setObject:t forKey:@"deviceToken"];
[[EMClient sharedClient]registerForRemoteNotificationsWithDeviceToken:token completion:^(EMError *aError) {
}];
// [[EMClient sharedClient] bindDeviceToken:token];
});
}else{
dispatch_async(dispatch_queue_create("updateDeviceToken", NULL), ^{
NSMutableString *t = [NSMutableString string];
const unsigned *tokenBytes = [deviceToken bytes];
for (int i=0; i<8; i++) {
[t appendFormat:@"%02x", tokenBytes[i]];
}
[[NSUserDefaults standardUserDefaults] setObject:t forKey:@"deviceToken"];
[[EMClient sharedClient]bindDeviceToken:deviceToken];
});
}
}
@end