Skip to content

Commit 9c3730c

Browse files
gouyelliotabarisain
authored andcommitted
all: 3.0
1 parent 37d4146 commit 9c3730c

18 files changed

+2355
-17
lines changed

BatchExtension.xcodeproj/project.pbxproj

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
51F7ECFC236092FF00E01CD2 /* BatchExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 51F7ECF2236092FF00E01CD2 /* BatchExtension.framework */; };
1616
51F7ED01236092FF00E01CD2 /* BatchExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51F7ED00236092FF00E01CD2 /* BatchExtensionTests.swift */; };
1717
51F7ED03236092FF00E01CD2 /* BatchExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 51F7ECF5236092FF00E01CD2 /* BatchExtension.h */; settings = {ATTRIBUTES = (Public, ); }; };
18+
6224E0E623F43C8100514B9D /* DisplayReceipt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6224E0E323F43C8100514B9D /* DisplayReceipt.swift */; };
19+
6224E0E723F43C8100514B9D /* DisplayReceiptCacheHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6224E0E423F43C8100514B9D /* DisplayReceiptCacheHelper.swift */; };
20+
6224E0E823F43C8100514B9D /* DisplayReceiptHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6224E0E523F43C8100514B9D /* DisplayReceiptHelper.swift */; };
21+
6224E0F023F43CA000514B9D /* Reader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6224E0EA23F43CA000514B9D /* Reader.swift */; };
22+
6224E0F123F43CA000514B9D /* Reader+Optionals.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6224E0EB23F43CA000514B9D /* Reader+Optionals.swift */; };
23+
6224E0F223F43CA000514B9D /* DataStream.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6224E0EC23F43CA000514B9D /* DataStream.swift */; };
24+
6224E0F323F43CA000514B9D /* FlatValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6224E0ED23F43CA000514B9D /* FlatValue.swift */; };
25+
6224E0F423F43CA000514B9D /* Writer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6224E0EE23F43CA000514B9D /* Writer.swift */; };
26+
6224E0F523F43CA000514B9D /* Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6224E0EF23F43CA000514B9D /* Types.swift */; };
1827
/* End PBXBuildFile section */
1928

2029
/* Begin PBXContainerItemProxy section */
@@ -39,6 +48,15 @@
3948
51F7ECFB236092FF00E01CD2 /* BatchExtensionTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BatchExtensionTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
4049
51F7ED00236092FF00E01CD2 /* BatchExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatchExtensionTests.swift; sourceTree = "<group>"; };
4150
51F7ED02236092FF00E01CD2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
51+
6224E0E323F43C8100514B9D /* DisplayReceipt.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DisplayReceipt.swift; sourceTree = "<group>"; };
52+
6224E0E423F43C8100514B9D /* DisplayReceiptCacheHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DisplayReceiptCacheHelper.swift; sourceTree = "<group>"; };
53+
6224E0E523F43C8100514B9D /* DisplayReceiptHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DisplayReceiptHelper.swift; sourceTree = "<group>"; };
54+
6224E0EA23F43CA000514B9D /* Reader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reader.swift; sourceTree = "<group>"; };
55+
6224E0EB23F43CA000514B9D /* Reader+Optionals.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Reader+Optionals.swift"; sourceTree = "<group>"; };
56+
6224E0EC23F43CA000514B9D /* DataStream.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataStream.swift; sourceTree = "<group>"; };
57+
6224E0ED23F43CA000514B9D /* FlatValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlatValue.swift; sourceTree = "<group>"; };
58+
6224E0EE23F43CA000514B9D /* Writer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Writer.swift; sourceTree = "<group>"; };
59+
6224E0EF23F43CA000514B9D /* Types.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Types.swift; sourceTree = "<group>"; };
4260
/* End PBXFileReference section */
4361

4462
/* Begin PBXFrameworksBuildPhase section */
@@ -63,6 +81,8 @@
6381
514E86C72362EBEC00E42FF4 /* Swift */ = {
6482
isa = PBXGroup;
6583
children = (
84+
6224E0E923F43CA000514B9D /* MessagePack */,
85+
6224E0E223F43C8100514B9D /* Display Receipt */,
6686
514E86D52362FAC300E42FF4 /* SwiftPM */,
6787
514E86C82362EBEC00E42FF4 /* Consts.swift */,
6888
514E86C92362EBEC00E42FF4 /* Rich Notifications */,
@@ -133,6 +153,29 @@
133153
path = Tests;
134154
sourceTree = "<group>";
135155
};
156+
6224E0E223F43C8100514B9D /* Display Receipt */ = {
157+
isa = PBXGroup;
158+
children = (
159+
6224E0E323F43C8100514B9D /* DisplayReceipt.swift */,
160+
6224E0E423F43C8100514B9D /* DisplayReceiptCacheHelper.swift */,
161+
6224E0E523F43C8100514B9D /* DisplayReceiptHelper.swift */,
162+
);
163+
path = "Display Receipt";
164+
sourceTree = "<group>";
165+
};
166+
6224E0E923F43CA000514B9D /* MessagePack */ = {
167+
isa = PBXGroup;
168+
children = (
169+
6224E0EA23F43CA000514B9D /* Reader.swift */,
170+
6224E0EB23F43CA000514B9D /* Reader+Optionals.swift */,
171+
6224E0EC23F43CA000514B9D /* DataStream.swift */,
172+
6224E0ED23F43CA000514B9D /* FlatValue.swift */,
173+
6224E0EE23F43CA000514B9D /* Writer.swift */,
174+
6224E0EF23F43CA000514B9D /* Types.swift */,
175+
);
176+
path = MessagePack;
177+
sourceTree = "<group>";
178+
};
136179
/* End PBXGroup section */
137180

138181
/* Begin PBXHeadersBuildPhase section */
@@ -191,7 +234,7 @@
191234
isa = PBXProject;
192235
attributes = {
193236
LastSwiftUpdateCheck = 1110;
194-
LastUpgradeCheck = 1110;
237+
LastUpgradeCheck = 1150;
195238
ORGANIZATIONNAME = Batch;
196239
TargetAttributes = {
197240
51F7ECF1236092FF00E01CD2 = {
@@ -243,10 +286,19 @@
243286
isa = PBXSourcesBuildPhase;
244287
buildActionMask = 2147483647;
245288
files = (
289+
6224E0F023F43CA000514B9D /* Reader.swift in Sources */,
290+
6224E0F223F43CA000514B9D /* DataStream.swift in Sources */,
291+
6224E0F523F43CA000514B9D /* Types.swift in Sources */,
246292
514E86D02362EBEC00E42FF4 /* BAENotificationServiceExtension.m in Sources */,
293+
6224E0E723F43C8100514B9D /* DisplayReceiptCacheHelper.swift in Sources */,
294+
6224E0E623F43C8100514B9D /* DisplayReceipt.swift in Sources */,
247295
514E86D72362FC1E00E42FF4 /* BAENotificationServiceExtension.swift in Sources */,
296+
6224E0F123F43CA000514B9D /* Reader+Optionals.swift in Sources */,
297+
6224E0F423F43CA000514B9D /* Writer.swift in Sources */,
248298
514E86CF2362EBEC00E42FF4 /* RichNotificationHelper.swift in Sources */,
249299
514E86CE2362EBEC00E42FF4 /* Consts.swift in Sources */,
300+
6224E0F323F43CA000514B9D /* FlatValue.swift in Sources */,
301+
6224E0E823F43C8100514B9D /* DisplayReceiptHelper.swift in Sources */,
250302
);
251303
runOnlyForDeploymentPostprocessing = 0;
252304
};
@@ -393,10 +445,12 @@
393445
isa = XCBuildConfiguration;
394446
buildSettings = {
395447
APPLICATION_EXTENSION_API_ONLY = YES;
396-
CODE_SIGN_STYLE = Manual;
448+
CODE_SIGN_IDENTITY = "";
449+
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
450+
CODE_SIGN_STYLE = Automatic;
397451
CURRENT_PROJECT_VERSION = 2;
398452
DEFINES_MODULE = YES;
399-
DEVELOPMENT_TEAM = "";
453+
DEVELOPMENT_TEAM = U5K2ETC2Y6;
400454
DYLIB_COMPATIBILITY_VERSION = 1;
401455
DYLIB_CURRENT_VERSION = 1;
402456
DYLIB_INSTALL_NAME_BASE = "@rpath";
@@ -423,10 +477,12 @@
423477
isa = XCBuildConfiguration;
424478
buildSettings = {
425479
APPLICATION_EXTENSION_API_ONLY = YES;
426-
CODE_SIGN_STYLE = Manual;
480+
CODE_SIGN_IDENTITY = "";
481+
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
482+
CODE_SIGN_STYLE = Automatic;
427483
CURRENT_PROJECT_VERSION = 2;
428484
DEFINES_MODULE = YES;
429-
DEVELOPMENT_TEAM = "";
485+
DEVELOPMENT_TEAM = U5K2ETC2Y6;
430486
DYLIB_COMPATIBILITY_VERSION = 1;
431487
DYLIB_CURRENT_VERSION = 1;
432488
DYLIB_INSTALL_NAME_BASE = "@rpath";
@@ -454,6 +510,7 @@
454510
buildSettings = {
455511
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
456512
CODE_SIGN_STYLE = Automatic;
513+
DEVELOPMENT_TEAM = U5K2ETC2Y6;
457514
INFOPLIST_FILE = Tests/Info.plist;
458515
LD_RUNPATH_SEARCH_PATHS = (
459516
"$(inherited)",
@@ -472,6 +529,7 @@
472529
buildSettings = {
473530
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
474531
CODE_SIGN_STYLE = Automatic;
532+
DEVELOPMENT_TEAM = U5K2ETC2Y6;
475533
INFOPLIST_FILE = Tests/Info.plist;
476534
LD_RUNPATH_SEARCH_PATHS = (
477535
"$(inherited)",

BatchExtension.xcodeproj/xcshareddata/xcschemes/BatchExtension.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1110"
3+
LastUpgradeVersion = "1150"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Sources/ObjC/BAENotificationServiceExtension.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
Drop-in replacement for UNNotificationServiceExtension.
1414
1515
Simply set it as your base class without overriding any methods and Batch will automatically:
16-
- Remove duplicate notifications
1716
- Download and set rich content
17+
- Send display receipts
1818
*/
1919
@interface BAENotificationServiceExtension : UNNotificationServiceExtension
2020

Sources/ObjC/BAENotificationServiceExtension.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,30 @@
1111

1212
@implementation BAENotificationServiceExtension
1313
{
14-
BAERichNotificationHelper *_helper;
14+
BAERichNotificationHelper *_richNotificationHelper;
15+
BAEDisplayReceiptHelper *_displayReceiptHelper;
1516
}
1617

1718
- (instancetype)init
1819
{
1920
self = [super init];
2021
if (self) {
21-
_helper = [BAERichNotificationHelper new];
22+
_richNotificationHelper = [BAERichNotificationHelper new];
23+
_displayReceiptHelper = [BAEDisplayReceiptHelper new];
2224
}
2325
return self;
2426
}
2527

2628
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent *contentToDeliver))contentHandler
2729
{
28-
[_helper didReceiveNotificationRequest:request withContentHandler:contentHandler];
30+
[_richNotificationHelper didReceiveNotificationRequest:request withContentHandler:contentHandler];
31+
[_displayReceiptHelper didReceiveNotificationRequest:request];
2932
}
3033

3134
- (void)serviceExtensionTimeWillExpire
3235
{
33-
[_helper serviceExtensionTimeWillExpire];
36+
[_richNotificationHelper serviceExtensionTimeWillExpire];
37+
[_displayReceiptHelper serviceExtensionTimeWillExpire];
3438
}
3539

3640
@end

Sources/Swift/Consts.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,14 @@ struct Consts {
1111
static let timeoutIntervalSecs = 20
1212
static let attachmentIdentifier = "batch_rich_attachment"
1313
static let errorDomain = "com.batch.extension.richnotificationhelper"
14+
15+
static let receiptAppGroupDirectory = "group.com.batch.enterprise"
16+
static let receiptCacheDirectory = "com.batch.displayreceipts"
17+
static let receiptCacheFileFormat = "%@.bin"
18+
static let receiptMaxCacheFile = 5
19+
static let receiptMaxAgeFromCache = 2592000.0 // 30 days in seconds
20+
static let receiptHeaderExtVersion = "x-batch-ext-version"
21+
static let receiptHeaderSchemaVersion = "x-batch-protocol-version"
22+
static let receiptSchemaVersion = "1.0.0"
23+
static let receiptErrorDomain = "com.batch.extension.displayreceipthelper"
1424
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//
2+
// DisplayReceipt.swift
3+
// BatchExtension
4+
//
5+
// Copyright © 2020 Batch. All rights reserved.
6+
//
7+
8+
import Foundation
9+
10+
internal class DisplayReceipt {
11+
12+
let timestamp: UInt64
13+
var replay: Bool
14+
var sendAttempt: UInt32
15+
let od: [AnyHashable: Any?]?
16+
let ed: [AnyHashable: Any?]?
17+
18+
init(timestamp: UInt64, replay: Bool, sendAttempt: UInt32, od: [AnyHashable: Any?]?, ed: [AnyHashable: Any?]?) {
19+
self.timestamp = timestamp
20+
self.replay = replay
21+
self.sendAttempt = sendAttempt
22+
self.od = od
23+
self.ed = ed
24+
}
25+
26+
internal func pack(toWriter packer: inout MessagePackWriter) throws {
27+
do {
28+
packer.pack(timestamp)
29+
packer.pack(replay)
30+
packer.pack(sendAttempt)
31+
32+
if let od = od, !od.isEmpty {
33+
try packer.packAny(od)
34+
} else {
35+
packer.packNil()
36+
}
37+
38+
if let ed = ed, !ed.isEmpty {
39+
try packer.packAny(ed)
40+
} else {
41+
packer.packNil()
42+
}
43+
} catch {
44+
throw DisplayReceiptHelperError.packError(underlyingError: error)
45+
}
46+
}
47+
48+
func pack() throws -> Data {
49+
var packer = MessagePackWriter()
50+
do {
51+
try pack(toWriter: &packer)
52+
} catch {
53+
throw error
54+
}
55+
return packer.data
56+
}
57+
58+
class func unpack(from data: Data) throws -> DisplayReceipt {
59+
do {
60+
var reader = MessagePackReader(from: data)
61+
let timestamp = try reader.read(UInt64.self)
62+
let replay = try reader.read(Bool.self)
63+
let sendAttempt = try reader.read(UInt32.self)
64+
let od = try reader.readOptionalDictionary()
65+
let ed = try reader.readOptionalDictionary()
66+
return DisplayReceipt(timestamp: timestamp, replay: replay, sendAttempt: UInt32(sendAttempt), od: od, ed: ed)
67+
} catch {
68+
throw DisplayReceiptHelperError.unpackError(underlyingError: error)
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)