1111#import " UIDevice+AIAdditions.h"
1212
1313
14+ static const int kTransactionIdCount = 10 ;
15+
1416#pragma mark public implementation
1517@implementation AIActivityState
1618
@@ -29,6 +31,7 @@ - (id)init {
2931 self.lastActivity = -1 ;
3032 self.createdAt = -1 ;
3133 self.lastInterval = -1 ;
34+ self.transactionIds = [NSMutableArray arrayWithCapacity: kTransactionIdCount ];
3235
3336 return self;
3437}
@@ -52,6 +55,22 @@ - (void)injectEventAttributes:(AIPackageBuilder *)builder {
5255 builder.eventCount = self.eventCount ;
5356}
5457
58+ - (void )addTransactionId : (NSString *)transactionId {
59+ if (self.transactionIds == nil ) { // create array
60+ self.transactionIds = [NSMutableArray arrayWithCapacity: kTransactionIdCount ];
61+ }
62+
63+ if (self.transactionIds .count == kTransactionIdCount ) {
64+ [self .transactionIds removeObjectAtIndex: 0 ]; // make space
65+ }
66+
67+ [self .transactionIds addObject: transactionId]; // add new ID
68+ }
69+
70+ - (BOOL )findTransactionId : (NSString *)transactionId {
71+ return [self .transactionIds containsObject: transactionId];
72+ }
73+
5574- (NSString *)description {
5675 return [NSString stringWithFormat: @" ec:%d sc:%d ssc:%d sl:%.1f ts:%.1f la:%.1f " ,
5776 self .eventCount, self .sessionCount, self .subsessionCount, self .sessionLength,
@@ -72,26 +91,32 @@ - (id)initWithCoder:(NSCoder *)decoder {
7291 self.createdAt = [decoder decodeDoubleForKey: @" createdAt" ];
7392 self.lastActivity = [decoder decodeDoubleForKey: @" lastActivity" ];
7493 self.uuid = [decoder decodeObjectForKey: @" uuid" ];
94+ self.transactionIds = [decoder decodeObjectForKey: @" transactionIds" ];
7595
7696 // create UUID for migrating devices
7797 if (self.uuid == nil ) {
7898 self.uuid = [UIDevice.currentDevice aiCreateUuid ];
7999 }
80100
101+ if (self.transactionIds == nil ) {
102+ self.transactionIds = [NSMutableArray arrayWithCapacity: kTransactionIdCount ];
103+ }
104+
81105 self.lastInterval = -1 ;
82106
83107 return self;
84108}
85109
86110- (void )encodeWithCoder : (NSCoder *)encoder {
87- [encoder encodeInt: self .eventCount forKey: @" eventCount" ];
88- [encoder encodeInt: self .sessionCount forKey: @" sessionCount" ];
89- [encoder encodeInt: self .subsessionCount forKey: @" subsessionCount" ];
90- [encoder encodeDouble: self .sessionLength forKey: @" sessionLength" ];
91- [encoder encodeDouble: self .timeSpent forKey: @" timeSpent" ];
92- [encoder encodeDouble: self .createdAt forKey: @" createdAt" ];
93- [encoder encodeDouble: self .lastActivity forKey: @" lastActivity" ];
94- [encoder encodeObject: self .uuid forKey: @" uuid" ];
111+ [encoder encodeInt: self .eventCount forKey: @" eventCount" ];
112+ [encoder encodeInt: self .sessionCount forKey: @" sessionCount" ];
113+ [encoder encodeInt: self .subsessionCount forKey: @" subsessionCount" ];
114+ [encoder encodeDouble: self .sessionLength forKey: @" sessionLength" ];
115+ [encoder encodeDouble: self .timeSpent forKey: @" timeSpent" ];
116+ [encoder encodeDouble: self .createdAt forKey: @" createdAt" ];
117+ [encoder encodeDouble: self .lastActivity forKey: @" lastActivity" ];
118+ [encoder encodeObject: self .uuid forKey: @" uuid" ];
119+ [encoder encodeObject: self .transactionIds forKey: @" transactionIds" ];
95120}
96121
97122
0 commit comments