-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathNSPTestPush.xm
81 lines (71 loc) · 2.76 KB
/
NSPTestPush.xm
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#import "NSPTestPush.h"
@implementation NSPTestPush
+ (void)load {
[self sharedInstance];
}
+ (id)sharedInstance {
static dispatch_once_t once = 0;
__strong static id sharedInstance = nil;
dispatch_once(&once, ^{
sharedInstance = [self new];
});
return sharedInstance;
}
- (id)init {
if (self = [super init]) {
CPDistributedMessagingCenter *messagingCenter =
[CPDistributedMessagingCenter centerNamed:PUSHER_MESSAGING_CENTER_NAME];
[messagingCenter runServerOnCurrentThread];
[messagingCenter
registerForMessageName:PUSHER_TEST_PUSH_MESSAGE_NAME
target:self
selector:@selector(handleMessageNamed:withUserInfo:)];
}
return self;
}
- (NSDictionary *)handleMessageNamed:(NSString *)name
withUserInfo:(NSDictionary *)userInfo {
NSString *service = userInfo[@"service"];
BBServer *bbServer = [BBServer pusherSharedInstance];
if (service == nil || ![service isKindOfClass:NSString.class] ||
service.length < 1 || bbServer == nil ||
![bbServer isKindOfClass:BBServer.class]) {
return @{@"success" : @NO};
}
BBBulletin *bulletin = [BBBulletin new];
bulletin.title = PUSHER_TEST_NOTIFICATION_TITLE;
bulletin.subtitle = PUSHER_TEST_NOTIFICATION_SUBTITLE;
bulletin.message = PUSHER_TEST_NOTIFICATION_MESSAGE;
bulletin.date = [NSDate date];
bulletin.sectionID = PUSHER_TEST_NOTIFICATION_SECTION_ID;
NSURL *attachmentURL =
[NSURL fileURLWithPath:XStr(@"%@/[email protected]", PUSHER_BUNDLE_PATH)];
BBAttachmentMetadata *attachment;
// iOS 14
if ([[%c(BBAttachmentMetadata) alloc]
respondsToSelector:@selector(_initWithType:URL:identifier:uniformType:thumbnailGeneratorUserInfo:thumbnailHidden:hiddenFromDefaultExpandedView:)]) {
attachment = [[%c(BBAttachmentMetadata) alloc]
_initWithType:1
URL:attachmentURL
identifier:@"TestImage"
// no idea what this is supposed to be
uniformType:@"TestImageUniformType"
// no idea what this is supposed to be
thumbnailGeneratorUserInfo:nil
thumbnailHidden:true
hiddenFromDefaultExpandedView:false];
} else {
attachment = [[%c(BBAttachmentMetadata) alloc] _initWithUUID:@"TestImage" type:1 URL:attachmentURL];
}
[bulletin setPrimaryAttachment:attachment];
[bbServer
sendToPusherService:service
bulletin:bulletin
appID:bulletin.sectionID
appName:PUSHER_TEST_NOTIFICATION_APP_NAME
title:bulletin.title
message:XStr(@"%@\n%@", bulletin.subtitle, bulletin.message)
isTest:YES];
return @{@"success" : @YES};
}
@end