I want to send a message from my client app to other devices subscribed to a specific topic using Firebase. Firebase docs telling me how to send this request in order to deploy this message:
Topic HTTP POST request Send to a single topic:
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to" : /topics/foo-bar",
"priority" : "high",
"notification" : {
"body" : "This is a Firebase Cloud Messaging Topic Message!",
"title" : "FCM Message",
}
}
I don't know how to implement this in my code and I tried but with no success, Here's my code:
NSDictionary *dic1 = @{
@"body : " : @"This is a Firebase Cloud Messaging Topic Message",
@"title : " : @"FCM Message"
};
NSDictionary *dic2 = @{
@"to : " : @"/topics/news",
@"priority : " : @"high",
@"notification : " : dic1
};
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"https://fcm.googleapis.com/fcm/send"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"key=MYKEY" forHTTPHeaderField:@"Authorization"];
NSError *error;
[request setHTTPBody:[NSJSONSerialization dataWithJSONObject:dic1 options:NSJSONWritingPrettyPrinted error:&error]];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
Please help. Thanks