Skip to content

Commit

Permalink
Merge pull request #615 from adotkhan/master
Browse files Browse the repository at this point in the history
Add ApplicationParameters to iOS library
  • Loading branch information
rod-hynes authored Aug 22, 2022
2 parents cb4e5e2 + b1e7cc1 commit 999f677
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ WWAN or vice versa or VPN state changed
*/
- (void)onServerAlert:(NSString * _Nonnull)reason :(NSString * _Nonnull)subject :(NSArray * _Nonnull)actionURLs;

/*!
Called when tunnel-core receives "ApplicationParameters" from the server.
*/
- (void)onApplicationParameter:(NSString * _Nonnull)key :(id _Nonnull)value;

@end

/*!
Expand Down
22 changes: 22 additions & 0 deletions MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,29 @@ - (void)handlePsiphonNotice:(NSString * _Nonnull)noticeJSON {
});
}
}
else if ([noticeType isEqualToString:@"ApplicationParameter"]) {

id key = [notice valueForKeyPath:@"data.key"];
if (![key isKindOfClass:[NSString class]]) {
[self logMessage:[NSString stringWithFormat: @"ApplicationParameter notice missing data.key: %@", noticeJSON]];
return;
}

id maybeValue = [notice valueForKeyPath:@"data.value"];
if (!maybeValue) {
[self logMessage:[NSString stringWithFormat: @"ApplicationParameter notice missing data.value: %@", noticeJSON]];
return;
}

// value is nil if data.value is NSNull.
id value = maybeValue == [NSNull null] ? nil : maybeValue;

if ([self.tunneledAppDelegate respondsToSelector:@selector(onApplicationParameter::)]) {
dispatch_sync(self->callbackQueue, ^{
[self.tunneledAppDelegate onApplicationParameter:(NSString *)key :value];
});
}
}
else if ([noticeType isEqualToString:@"InternalError"]) {
internalError = TRUE;
}
Expand Down

0 comments on commit 999f677

Please sign in to comment.