Skip to content

Commit

Permalink
Adds ObjC completion handler for sendBehaviorData.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Chen committed Apr 27, 2017
1 parent 894f8d1 commit a7b04ad
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
10 changes: 10 additions & 0 deletions Example/ObjcExample.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,14 @@ - (void) getAudience{
}];
}

- (void) sendBehaviorWithHandler{
[DMP sendBehaviorDataWithHandler: ^(NSError * _Nullable error){
if (error != nil){
NSLog(@"error:: %@", error.description);
} else {
NSLog(@"sendBehaviorDataWithHandler success");
}
}];
}

@end
9 changes: 9 additions & 0 deletions Pod/Classes/DMP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ open class DMP:NSObject{
}
}

/**
Used by objective-c code that does not support generics. Do not use in swift. Use sendBehaviorData instead
*/
@objc open class func sendBehaviorDataWithHandler(_ handler:@escaping (_ error: NSError?)->Void) {
sendBehaviorData{ result in
handler(result.error as NSError?)
}
}

/**
Sends the collected behavior data to the Lotame server. Returns errors
to the completion handler.
Expand Down
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ LotameDMP must be imported by any file using the library.
import LotameDMP
```

or for objective-c
or for Objective-C

```objective-c
#import "LotameDMP-Swift.h"
Expand All @@ -82,7 +82,7 @@ LotameDMP is a singleton that must be initialized with a client id once before u
DMP.initialize("YOUR_CLIENT_ID_NUMBER")
```

or for objective-c
or for Objective-C

```objective-c
[DMP initialize:@"YOUR_CLIENT_ID_NUMBER_"];
Expand All @@ -100,7 +100,7 @@ DMP.addBehaviorData(behaviorId: 1)
DMP.addBehaviorData(opportunityId: 1)
```

or for objective-c
or for Objective-C

```objective-c
[DMP addBehaviorData:@"value" forType: @"type"];
Expand All @@ -114,7 +114,7 @@ It must be sent to the server to record the behaviors:
DMP.sendBehaviorData()
```

or for objective-c
or for Objective-C

```objective-c
[DMP sendBehaviorData];
Expand All @@ -133,6 +133,18 @@ DMP.sendBehaviorData(){
}
```

or for Objective-C

```objective-c
[DMP sendBehaviorDataWithHandler: ^(NSError * _Nullable error){
if (error != nil){
//Failure
} else {
//Success
}
}];
```
### Get Audience Data
Get the audience data with the following command:
Expand All @@ -148,7 +160,7 @@ DMP.getAudienceData{
}
```

or for objective-c
or for Objective-C

```objective-c
[DMP getAudienceDataWithHandler:^(LotameProfile * _Nullable profile, BOOL success) {
Expand All @@ -168,7 +180,7 @@ To indicate that a new session has started, use the following command:
DMP.startNewSession()
```

or for objective-c
or for Objective-C

```objective-c
[DMP startNewSession];
Expand Down

0 comments on commit a7b04ad

Please sign in to comment.