Skip to content

Commit a6673b3

Browse files
committed
incremental tags support, new JSON writing
1 parent c1a6e9a commit a6673b3

22 files changed

+1180
-106
lines changed

SDK Sample Projects/iPhone-Phonegap/Phonegap-Push/Plugins/PWLocationTracker.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#import "PWLocationTracker.h"
77
#import <UIKit/UIKit.h>
88

9+
//comment this line to disable location tracking for geo-push notifications and dependency on CoreLocation.framework
10+
#define USE_LOCATION
11+
912
static CGFloat const kMinUpdateDistance = 10.f;
1013
static NSTimeInterval const kMinUpdateTime = 10.f;
1114

@@ -25,8 +28,10 @@ - (id)init {
2528
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
2629
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
2730

31+
#ifdef USE_LOCATION
2832
self.locationManager = [[CLLocationManager alloc] init];
2933
self.locationManager.delegate = self;
34+
#endif
3035
//[self.locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
3136

3237
self.enabled = false;

SDK Sample Projects/iPhone/Classes/ViewController.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ - (void) submitAction:(id)sender {
4747
NSDictionary *tags = [NSDictionary dictionaryWithObjectsAndKeys:
4848
[aliasField text], @"Alias",
4949
[NSNumber numberWithInt:[favNumField.text intValue]], @"FavNumber",
50+
// @"#pwinc#10", @"price",
51+
[PWTags incrementalTagWithInteger:5], @"price",
5052
nil];
5153

5254
[[PushNotificationManager pushManager] setTags:tags];

SDK Sample Projects/iPhone/PushNotificationManager/Classes/PWApplicationEventRequest.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ - (NSString *) methodName {
1616
- (NSDictionary *) requestDictionary {
1717
NSMutableDictionary *dict = [self baseDictionary];
1818

19-
[dict setObject:[self encodeString:goal] forKey:@"goal"];
19+
[dict setObject:goal forKey:@"goal"];
2020

2121
if(count != nil)
22-
[dict setObject:[self encodeInt:[count intValue]] forKey:@"count"];
22+
[dict setObject:count forKey:@"count"];
2323

2424
return dict;
2525
}

SDK Sample Projects/iPhone/PushNotificationManager/Classes/PWGetNearestZoneRequest.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ - (NSString *) methodName {
1616
- (NSDictionary *) requestDictionary {
1717
NSMutableDictionary *dict = [self baseDictionary];
1818

19-
[dict setObject:[self encodeDouble:coordinate.latitude] forKey:@"lat"];
20-
[dict setObject:[self encodeDouble:coordinate.longitude] forKey:@"lng"];
19+
[dict setObject:[NSNumber numberWithDouble:coordinate.latitude] forKey:@"lat"];
20+
[dict setObject:[NSNumber numberWithDouble:coordinate.longitude] forKey:@"lng"];
2121

2222
return dict;
2323
}

SDK Sample Projects/iPhone/PushNotificationManager/Classes/PWLocationTracker.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#import "PWLocationTracker.h"
77
#import <UIKit/UIKit.h>
88

9+
//comment this line to disable location tracking for geo-push notifications and dependency on CoreLocation.framework
10+
#define USE_LOCATION
11+
912
static CGFloat const kMinUpdateDistance = 10.f;
1013
static NSTimeInterval const kMinUpdateTime = 10.f;
1114

@@ -25,8 +28,10 @@ - (id)init {
2528
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
2629
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
2730

31+
#ifdef USE_LOCATION
2832
self.locationManager = [[CLLocationManager alloc] init];
2933
self.locationManager.delegate = self;
34+
#endif
3035
//[self.locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
3136

3237
self.enabled = false;

SDK Sample Projects/iPhone/PushNotificationManager/Classes/PWPushStatRequest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ - (NSDictionary *) requestDictionary {
1717
NSMutableDictionary *dict = [self baseDictionary];
1818

1919
if(hash != nil)
20-
[dict setObject:[self encodeString:hash] forKey:@"hash"];
20+
[dict setObject:hash forKey:@"hash"];
2121

2222
return dict;
2323
}

SDK Sample Projects/iPhone/PushNotificationManager/Classes/PWRegisterDeviceRequest.m

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@ - (NSString *) methodName {
1818
- (NSDictionary *) requestDictionary {
1919
NSMutableDictionary *dict = [self baseDictionary];
2020

21-
[dict setObject:[self encodeInt:1] forKey:@"device_type"];
22-
[dict setObject:[self encodeString:pushToken] forKey:@"push_token"];
23-
[dict setObject:[self encodeString:language] forKey:@"language"];
24-
[dict setObject:[self encodeString:timeZone] forKey:@"timezone"];
21+
[dict setObject:[NSNumber numberWithInt:1] forKey:@"device_type"];
22+
[dict setObject:pushToken forKey:@"push_token"];
23+
[dict setObject:language forKey:@"language"];
24+
[dict setObject:timeZone forKey:@"timezone"];
2525

2626
BOOL sandbox = ![PushNotificationManager getAPSProductionStatus];
27-
[dict setObject:[self encodeString:sandbox ? @"sandbox" : @"production"] forKey:@"gateway"];
27+
if(sandbox)
28+
[dict setObject:@"sandbox" forKey:@"gateway"];
29+
else
30+
[dict setObject:@"production" forKey:@"gateway"];
2831

2932
NSString * package = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"];
30-
[dict setObject:[self encodeString:package] forKey:@"package"];
33+
[dict setObject:package forKey:@"package"];
3134

3235
return dict;
3336
}

SDK Sample Projects/iPhone/PushNotificationManager/Classes/PWRequest.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,7 @@
1313
@property (nonatomic, copy) NSString *hwid;
1414

1515
- (NSString *) methodName;
16-
- (NSDictionary *) requestDictionary; //Please note that all values will be processed as strings
17-
18-
19-
- (NSString *) encodeString: (NSString *) str;
20-
- (NSString *) encodeNumber: (NSNumber *) number;
21-
- (NSString *) encodeObject: (NSObject *) object;
22-
- (NSString *) encodeInt: (int) number;
23-
- (NSString *) encodeDouble: (double) number;
24-
- (NSString *) encodeFloat: (float) number;
16+
- (NSDictionary *) requestDictionary;
2517

2618
- (NSMutableDictionary *) baseDictionary;
2719

SDK Sample Projects/iPhone/PushNotificationManager/Classes/PWRequest.m

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,10 @@ - (NSDictionary *) requestDictionary {
1818
return nil;
1919
}
2020

21-
- (NSString *) encodeString: (NSString *) str {
22-
return [NSString stringWithFormat:@"\"%@\"", [str stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]];
23-
}
24-
25-
- (NSString *) encodeNumber: (NSNumber *) number {
26-
return [number stringValue];
27-
}
28-
29-
- (NSString *) encodeObject: (NSObject *) object {
30-
return [NSString stringWithFormat:@"%@", object];
31-
}
32-
33-
- (NSString *) encodeInt: (int) number {
34-
return [NSString stringWithFormat:@"%d", number];
35-
}
36-
37-
- (NSString *) encodeDouble: (double) number {
38-
return [NSString stringWithFormat:@"%f", number];
39-
}
40-
41-
- (NSString *) encodeFloat: (float) number {
42-
return [NSString stringWithFormat:@"%f", number];
43-
}
44-
4521
- (NSMutableDictionary *) baseDictionary {
4622
NSMutableDictionary *dict = [NSMutableDictionary new];
47-
[dict setObject:[self encodeString:appId] forKey:@"application"];
48-
[dict setObject:[self encodeString:hwid] forKey:@"hwid"];
23+
[dict setObject:appId forKey:@"application"];
24+
[dict setObject:hwid forKey:@"hwid"];
4925
return [dict autorelease];
5026
}
5127

SDK Sample Projects/iPhone/PushNotificationManager/Classes/PWRequestManager.m

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//
66

77
#import "PWRequestManager.h"
8+
#import "PW_SBJsonWriter.h"
89

910
@implementation PWRequestManager
1011

@@ -24,15 +25,13 @@ - (BOOL) sendRequest: (PWRequest *) request {
2425
}
2526

2627
- (BOOL) sendRequest: (PWRequest *) request error:(NSError **)retError {
27-
NSMutableArray *requestStringBuilder = [NSMutableArray new];
2828
NSDictionary *requestDict = [request requestDictionary];
2929

30-
for (NSString *key in [requestDict allKeys]) {
31-
[requestStringBuilder addObject:[NSString stringWithFormat:@"\"%@\":%@", key, [requestDict objectForKey:key]]];
32-
}
33-
NSString *requestString = [requestStringBuilder componentsJoinedByString:@", "];
34-
NSString *jsonRequestData = [NSString stringWithFormat:@"{\"request\":{%@}}", requestString];
35-
[requestStringBuilder release];
30+
PW_SBJsonWriter * json = [[PW_SBJsonWriter alloc] init];
31+
NSString *requestString = [json stringWithObject:requestDict];
32+
[json release]; json = nil;
33+
34+
NSString *jsonRequestData = [NSString stringWithFormat:@"{\"request\":%@}", requestString];
3635

3736
#ifdef NOSSL
3837
NSString *requestUrl = [kServiceAddressNoSSL stringByAppendingString:[request methodName]];

0 commit comments

Comments
 (0)