Skip to content

Commit 2facf5f

Browse files
committed
postNotification now supports overriding the app_id.
1 parent ec9817d commit 2facf5f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ + (void)postNotification:(NSDictionary*)jsonData onSuccess:(OSResultSuccessBlock
738738
NSMutableURLRequest* request = [httpClient requestWithMethod:@"POST" path:@"notifications"];
739739

740740
NSMutableDictionary* dataDic = [[NSMutableDictionary alloc] initWithDictionary:jsonData];
741-
dataDic[@"app_id"] = app_id;
741+
dataDic[@"app_id"] = dataDic[@"app_id"] ?: app_id;
742742

743743
NSData* postData = [NSJSONSerialization dataWithJSONObject:dataDic options:0 error:nil];
744744
[request setHTTPBody:postData];

iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,6 +1936,27 @@ - (void)testSendTagsBeforeRegisterComplete {
19361936
XCTAssertEqualObjects(lastHTTPRequset[@"identifier"], @"0000000000000000000000000000000000000000000000000000000000000000");
19371937
}
19381938

1939+
1940+
- (void)testPostNotification {
1941+
[self initOneSignal];
1942+
[self runBackgroundThreads];
1943+
XCTAssertEqual(networkRequestCount, 1);
1944+
1945+
1946+
// Normal post should auto add add_id.
1947+
[OneSignal postNotification:@{@"contents": @{@"en": @"message body"}}];
1948+
XCTAssertEqual(networkRequestCount, 2);
1949+
XCTAssertEqualObjects(lastHTTPRequset[@"contents"][@"en"], @"message body");
1950+
XCTAssertEqualObjects(lastHTTPRequset[@"app_id"], @"b2f7f966-d8cc-11e4-bed1-df8f05be55ba");
1951+
1952+
// Should allow overriding the app_id
1953+
[OneSignal postNotification:@{@"contents": @{@"en": @"message body"}, @"app_id": @"override_app_UUID"}];
1954+
XCTAssertEqual(networkRequestCount, 3);
1955+
XCTAssertEqualObjects(lastHTTPRequset[@"contents"][@"en"], @"message body");
1956+
XCTAssertEqualObjects(lastHTTPRequset[@"app_id"], @"override_app_UUID");
1957+
}
1958+
1959+
19391960
- (void)testFirstInitWithNotificationsAlreadyDeclined {
19401961
[self backgroundModesDisabledInXcode];
19411962
notifTypesOverride = 0;

0 commit comments

Comments
 (0)