Skip to content

Commit 31d9266

Browse files
authored
Merge pull request #901 from OneSignal/outcomes
iOS bridge for Outcomes
2 parents 7dcd3db + 9a36baa commit 31d9266

File tree

4 files changed

+19
-43
lines changed

4 files changed

+19
-43
lines changed

examples/RNOneSignal/App.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ export default class App extends Component {
113113

114114
oneSignalInAppMessagingExamples() {
115115
// Add a single trigger with a value associated with it
116+
OneSignal.addTrigger('trigger1', 'one');
117+
118+
// Get trigger value for the key
116119
OneSignal.getTriggerValueForKey('trigger1')
117120
.then(response => {
118121
console.log('trigger1 value: ' + response);

index.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,6 @@ export default class OneSignal {
475475
static sendOutcome(name, callback=function(){}) {
476476
if (!checkIfInitialized()) return;
477477

478-
if (Platform.OS === "ios") {
479-
console.warn("OneSignal.sendOutcome is not yet supported on iOS");
480-
return;
481-
}
482-
483478
invariant(
484479
typeof callback === 'function',
485480
'Must provide a valid callback'
@@ -491,11 +486,6 @@ export default class OneSignal {
491486
static sendUniqueOutcome(name, callback=function(){}) {
492487
if (!checkIfInitialized()) return;
493488

494-
if (Platform.OS === "ios") {
495-
console.warn("OneSignal.sendUniqueOutcome is not yet supported on iOS");
496-
return;
497-
}
498-
499489
invariant(
500490
typeof callback === 'function',
501491
'Must provide a valid callback'
@@ -507,11 +497,6 @@ export default class OneSignal {
507497
static sendOutcomeWithValue(name, value, callback=function(){}) {
508498
if (!checkIfInitialized()) return;
509499

510-
if (Platform.OS === "ios") {
511-
console.warn("OneSignal.sendOutcomeWithValue is not yet supported on iOS");
512-
return;
513-
}
514-
515500
invariant(
516501
typeof callback === 'function',
517502
'Must provide a valid callback'

ios/RCTOneSignal/RCTOneSignalEventEmitter.m

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
377377
[OneSignal removeTriggerForKey:key];
378378
}
379379

380-
RCT_REMAP_METHOD(getTriggerValueForKey,
381-
key:(NSString *)key
380+
RCT_REMAP_METHOD(getTriggerValueForKey,
381+
key:(NSString *)key
382382
getTriggerValueForKeyResolver:(RCTPromiseResolveBlock)resolve
383383
rejecter:(RCTPromiseRejectBlock)reject) {
384384

@@ -404,42 +404,30 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
404404
@"clickUrl" : action.clickUrl.absoluteString ?: [NSNull null],
405405
@"firstClick" : @(action.firstClick),
406406
@"closesMessage" : @(action.closesMessage)
407-
};
407+
};
408408
[RCTOneSignalEventEmitter sendEventWithName:@"OneSignal-inAppMessageClicked" withBody:result];
409409
}];
410410
}
411411

412412
/*
413413
* Outcomes
414414
*/
415-
RCT_EXPORT_METHOD(sendOutcome:(NSString *)name withCallback:(RCTResponseSenderBlock)callback) {
416-
[OneSignal onesignal_Log:ONE_S_LL_ERROR message:@"Not implemented for iOS"];
417-
418-
// [OneSignal sendUniqueOutcome:name onSuccess:^(NSDictionary *result) {
419-
// callback(@[result]);
420-
// } onFailure:^(NSError *error){
421-
// callback(@[error.userInfo[@"error"] ?: error.localizedDescription]);
422-
// }];
415+
RCT_EXPORT_METHOD(sendOutcome:(NSString *)name :(RCTResponseSenderBlock)callback) {
416+
[OneSignal sendOutcome:name onSuccess:^(OSOutcomeEvent *outcome){
417+
callback(@[[outcome jsonRepresentation]]);
418+
}];
423419
}
424420

425-
RCT_EXPORT_METHOD(sendUniqueOutcome:(NSString *)name withCallback:(RCTResponseSenderBlock)callback) {
426-
[OneSignal onesignal_Log:ONE_S_LL_ERROR message:@"Not implemented for iOS"];
427-
428-
// [OneSignal sendUniqueOutcome:name onSuccess:^(NSDictionary *result) {
429-
// callback(@[result]);
430-
// } onFailure:^(NSError *error){
431-
// callback(@[error.userInfo[@"error"] ?: error.localizedDescription]);
432-
// }];
421+
RCT_EXPORT_METHOD(sendUniqueOutcome:(NSString *)name :(RCTResponseSenderBlock)callback) {
422+
[OneSignal sendUniqueOutcome:name onSuccess:^(OSOutcomeEvent *outcome){
423+
callback(@[[outcome jsonRepresentation]]);
424+
}];
433425
}
434426

435-
RCT_EXPORT_METHOD(sendOutcomeWithValue:(NSString *)name withValue:(float)value withCallback:(RCTResponseSenderBlock)callback) {
436-
[OneSignal onesignal_Log:ONE_S_LL_ERROR message:@"Not implemented for iOS"];
437-
438-
// [OneSignal sendOutcomeWithValue:name onSuccess:^(NSDictionary *result) {
439-
// callback(@[result]);
440-
// } onFailure:^(NSError *error){
441-
// callback(@[error.userInfo[@"error"] ?: error.localizedDescription]);
442-
// }];
427+
RCT_EXPORT_METHOD(sendOutcomeWithValue:(NSString *)name :(NSNumber * _Nonnull)value :(RCTResponseSenderBlock)callback) {
428+
[OneSignal sendOutcomeWithValue:name value:value onSuccess:^(OSOutcomeEvent *outcome){
429+
callback(@[[outcome jsonRepresentation]]);
430+
}];
443431
}
444432

445433
@end

react-native-onesignal.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ Pod::Spec.new do |s|
2222
# pod 'React', :path => '../node_modules/react-native/'
2323

2424
# The Native OneSignal-iOS-SDK from cocoapods.
25-
s.dependency 'OneSignal', '2.11.2'
25+
s.dependency 'OneSignal', '2.12.2'
2626
end

0 commit comments

Comments
 (0)