Skip to content

Commit

Permalink
Merge pull request #52 from adjust/development
Browse files Browse the repository at this point in the history
Add push token
  • Loading branch information
nonelse committed Jul 3, 2014
2 parents 761c19d + f8b500b commit 4f5792d
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Adjust.podspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Pod::Spec.new do |s|
s.name = "Adjust"
s.version = "3.3.4"
s.version = "3.3.5"
s.summary = "This is the iOS SDK of adjust. You can read more about it at http://adjust.com."
s.homepage = "http://adjust.com"
s.license = { :type => 'MIT', :file => 'MIT-LICENSE' }
s.author = { "Christian Wellenbrock" => "[email protected]" }
s.source = { :git => "https://github.com/adjust/ios_sdk.git", :tag => "v3.3.4" }
s.source = { :git => "https://github.com/adjust/ios_sdk.git", :tag => "v3.3.5" }
s.platform = :ios, '4.3'
s.framework = 'SystemConfiguration'
s.weak_framework = 'AdSupport', 'iAd'
Expand Down
6 changes: 3 additions & 3 deletions Adjust.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,9 @@
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0510;
ORGANIZATIONNAME = adjust;
ORGANIZATIONNAME = "adjust GmbH";
};
buildConfigurationList = 9679920818BBAE2800394606 /* Build configuration list for PBXProject "Adjust" */;
buildConfigurationList = 9679920818BBAE2800394606 /* Build configuration list for PBXProject "adjust" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
Expand Down Expand Up @@ -577,7 +577,7 @@
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
9679920818BBAE2800394606 /* Build configuration list for PBXProject "Adjust" */ = {
9679920818BBAE2800394606 /* Build configuration list for PBXProject "adjust" */ = {
isa = XCConfigurationList;
buildConfigurations = (
9679922E18BBAE2800394606 /* Debug */,
Expand Down
1 change: 1 addition & 0 deletions Adjust/AIActivityHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- (void)setEnabled:(BOOL)enabled;
- (BOOL)isEnabled;
- (void)readOpenUrl:(NSURL*)url;
- (void)savePushToken:(NSData *)pushToken;

@end

Expand Down
19 changes: 19 additions & 0 deletions Adjust/AIActivityHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ @interface AIActivityHandler()
@property (nonatomic, assign) BOOL internalEnabled;
@property (nonatomic, assign) BOOL isIad;
@property (nonatomic, copy) NSString *vendorId;
@property (nonatomic, copy) NSString *pushToken;

@end

Expand Down Expand Up @@ -153,6 +154,12 @@ - (void)readOpenUrl:(NSURL*)url {
});
}

- (void)savePushToken:(NSData *)pushToken {
dispatch_async(self.internalQueue, ^{
[self savePushTokenInternal:pushToken];
});
}

#pragma mark - internal
- (void)initInternal:(NSString *)yourAppToken {
if (![self checkAppTokenNotNil:yourAppToken]) return;
Expand Down Expand Up @@ -364,6 +371,17 @@ - (void) readOpenUrlInternal:(NSURL *)url {
[self.logger debug:@"Reattribution %@", adjustDeepLinks];
}

- (void) savePushTokenInternal:(NSData *)pushToken {
if (pushToken == nil) {
return;
}

NSString *token = [pushToken.description stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];

self.pushToken = token;
}

#pragma mark - private

// returns whether or not the activity state should be written
Expand Down Expand Up @@ -446,6 +464,7 @@ - (void)injectGeneralAttributes:(AIPackageBuilder *)builder {
builder.environment = self.environment;
builder.isIad = self.isIad;
builder.vendorId = self.vendorId;
builder.pushToken = self.pushToken;

if (self.trackMacMd5) {
builder.macShortMd5 = self.macShortMd5;
Expand Down
1 change: 1 addition & 0 deletions Adjust/AIPackageBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@property (nonatomic, assign) BOOL trackingEnabled;
@property (nonatomic, assign) BOOL isIad;
@property (nonatomic, copy) NSString *vendorId;
@property (nonatomic, copy) NSString *pushToken;

// sessions
@property (nonatomic, assign) int sessionCount;
Expand Down
1 change: 1 addition & 0 deletions Adjust/AIPackageBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ - (NSMutableDictionary *)defaultParameters {
[self parameters:parameters setInt:self.trackingEnabled forKey:@"tracking_enabled"];
[self parameters:parameters setBool:self.isIad forKey:@"is_iad"];
[self parameters:parameters setString:self.vendorId forKey:@"idfv"];
[self parameters:parameters setString:self.pushToken forKey:@"push_token"];

// session related (used for events as well)
[self parameters:parameters setInt:self.sessionCount forKey:@"session_count"];
Expand Down
2 changes: 1 addition & 1 deletion Adjust/AIUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <sys/xattr.h>

static NSString * const kBaseUrl = @"https://app.adjust.io";
static NSString * const kClientSdk = @"ios3.3.4";
static NSString * const kClientSdk = @"ios3.3.5";

static NSString * const kDateFormat = @"yyyy-MM-dd'T'HH:mm:ss'Z'Z";
static NSDateFormatter * dateFormat;
Expand Down
5 changes: 5 additions & 0 deletions Adjust/Adjust.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ static NSString * const AIEnvironmentProduction = @"production";
* an adjust deep link
*/
+ (void)appWillOpenUrl:(NSURL *)url;

/**
* Set the device token used by push notifications
*/
+ (void)setDeviceToken:(NSData *)deviceToken;
@end


Expand Down
4 changes: 4 additions & 0 deletions Adjust/Adjust.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,8 @@ + (void)appWillOpenUrl:(NSURL *)url {
[activityHandler readOpenUrl:url];
}

+ (void)setDeviceToken:(NSData *)deviceToken {
[activityHandler savePushToken:deviceToken];
}

@end
4 changes: 4 additions & 0 deletions AdjustTests/AIActivityHandlerMock.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,8 @@ - (void)readOpenUrl:(NSURL *)url {
[self.loggerMock test:[prefix stringByAppendingFormat:@"readOpenUrl"]];
}

- (void)savePushToken:(NSData *)pushToken {
[self.loggerMock test:[prefix stringByAppendingFormat:@"savePushToken"]];
}

@end
13 changes: 12 additions & 1 deletion AdjustTests/AIActivityHandlerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ - (void)testFirstRun
AIActivityPackage *activityPackage = (AIActivityPackage *) self.packageHandlerMock.packageQueue[0];

// check the Sdk version is being tested
XCTAssertEqual(@"ios3.3.4", activityPackage.clientSdk, @"%@", activityPackage.extendedString);
XCTAssertEqual(@"ios3.3.5", activityPackage.clientSdk, @"%@", activityPackage.extendedString);

// check the server url
XCTAssertEqual(@"https://app.adjust.io", AIUtil.baseUrl);
Expand Down Expand Up @@ -201,6 +201,8 @@ - (void)testEventsBuffered {
id<AIActivityHandler> activityHandler = [AIAdjustFactory activityHandlerWithAppToken:@"123456789012"];
[activityHandler setBufferEvents:YES];

[activityHandler savePushToken:nil];

// construct the parameters of the the event
NSDictionary *eventParameters = @{@"key": @"value", @"foo": @"bar" };

Expand Down Expand Up @@ -237,6 +239,8 @@ - (void)testEventsBuffered {
XCTAssert([(NSString *)eventPackageParameters[@"params"] isEqualToString:@"eyJrZXkiOiJ2YWx1ZSIsImZvbyI6ImJhciJ9"],
@"%@", eventPackage.extendedString);

XCTAssertNil(eventPackageParameters[@"push_token"], @"%@", eventPackage.extendedString);

// check that the event was buffered
XCTAssert([self.loggerMock containsMessage:AILogLevelInfo beginsWith:@"Buffered event 'abc123'"], @"%@", self.loggerMock);

Expand Down Expand Up @@ -297,6 +301,10 @@ - (void)testEventsNotBuffered {
id<AIActivityHandler> activityHandler = [AIAdjustFactory activityHandlerWithAppToken:@"123456789012"];
[activityHandler setBufferEvents:NO];

// test push token
const char bytes[] = "\xFC\x07\x21\xB6\xDF\xAD\x5E\xE1\x10\x97\x5B\xB2\xA2\x63\xDE\x00\x61\xCC\x70\x5B\x4A\x85\xA8\xAE\x3C\xCF\xBE\x7A\x66\x2F\xB1\xAB";
[activityHandler savePushToken:[NSData dataWithBytes:bytes length:(sizeof(bytes) - 1)]];

// the first is a normal event has parameters, the second a revenue
[activityHandler trackEvent:@"abc123" withParameters:nil];
[activityHandler trackRevenue:0 transactionId:nil forEvent:nil withParameters:nil];
Expand Down Expand Up @@ -326,6 +334,9 @@ - (void)testEventsNotBuffered {
// check the that the parameters were not injected
XCTAssertNil(eventPackageParameters[@"params"], @"%@", eventPackage.extendedString);

// check push token was correctly parsed
XCTAssert([@"fc0721b6dfad5ee110975bb2a263de0061cc705b4a85a8ae3ccfbe7a662fb1ab" isEqualToString:eventPackageParameters[@"push_token"]], @"%@", eventPackage.extendedString);

// check that the package handler was called
XCTAssert([self.loggerMock containsMessage:AILogLevelTest beginsWith:@"AIPackageHandler sendFirstPackage"],
@"%@", self.loggerMock);
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,19 @@ You can verify if the adjust SDK is currently active with the method
`isEnabled`. It is always possible to activate the adjust SDK by invoking
`setEnabled` with the enabled parameter as `YES`.
### 12. Push token
If your app receives notifications you can save the push token in the adjust SDK.
In the Project Navigator open the source file your Application Delegate. Find
or add the method `didRegisterForRemoteNotificationsWithDeviceToken` and add the following call to adjust:
```objc
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[Adjust setDeviceToken:deviceToken];
}
```

[adjust.com]: http://adjust.com
[cocoapods]: http://cocoapods.org
[dashboard]: http://adjust.com
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.4
3.3.5
8 changes: 4 additions & 4 deletions doc/migrate.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Migrate your adjust SDK for iOS to v3.3.4 from v3.0.0
## Migrate your adjust SDK for iOS to v3.3.5 from v3.0.0

We added an optional parameter `transactionId` to our `trackRevenue` methods. If you are tracking In-App Purchases you might want to pass in the transaction identifier provided by Apple to avoid duplicate revenue tracking. It should look roughly like this:

Expand Down Expand Up @@ -36,14 +36,14 @@ all adjust SDK calls.

![][rename]

3. Download version v3.3.4 and drag the new folder `Adjust` into your Xcode
3. Download version v3.3.5 and drag the new folder `Adjust` into your Xcode
Project Navigator.

![][drag]

4. Build your project to confirm that everything is properly connected again.

The adjust SDK v3.3.4 added delegate callbacks. Check out the [README] for
The adjust SDK v3.3.5 added delegate callbacks. Check out the [README] for
details.


Expand Down Expand Up @@ -99,7 +99,7 @@ meaningful at all times! Especially if you are tracking revenue.
1. The `appDidLaunch` method now expects your App Token instead of your App ID.
You can find your App Token in your [dashboard].
2. The adjust SDK for iOS 3.3.4 uses [ARC][arc]. If you haven't done already,
2. The adjust SDK for iOS 3.3.5 uses [ARC][arc]. If you haven't done already,
we recommend [transitioning your project to use ARC][transition] as well. If
you don't want to use ARC, you have to enable ARC for all files of the
adjust SDK. Please consult the [README] for details.
Expand Down
2 changes: 1 addition & 1 deletion doc/mixpanel.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The delegate function can be set as the following, to use the Mixpanel API:
- (void)adjustFinishedTrackingWithResponse:(AIResponseData *)responseData {
Mixpanel *mixpanel = [Mixpanel sharedInstance];

// The adjust properties properties will be sent
// The adjust properties will be sent
// with all future track calls.
if (responseData.network != nil)
[mixpanel registerSuperProperties:@{@"[Adjust]Network": responseData.network}];
Expand Down

0 comments on commit 4f5792d

Please sign in to comment.