使用 FCM iOS Objective-C 中的推送通知方法

Push Notification method in iOS Objective-C with FCM

我想知道我们可以在 Xcode 中使用什么方法和 Objective-C 代码来触发此函数中的推送通知:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// Print message ID.
NSLog(@"Message ID: %@", userInfo[@"gcm.message_id"]);

// Pring full message.
NSLog(@"%@", userInfo);

NSLog(@"Type: %@", userInfo[@"type"]);
}

注意:我尝试从 Firebase 控制台触发推送通知并且成功了,我收到了推送通知,

但现在我正在尝试使用 https://github.com/spacialdb/fcm

从我的后端服务器 (Rails) 发送推送通知

我从后端服务器发送通知时获得了数据,但我很困惑如何处理来自后端服务器的数据以触发 iOS 中的推送通知,我可以使用什么方法?

编辑:我可以在 didReceiveRemoteNotification

中使用此代码收到通知
UILocalNotification* n1 = [[UILocalNotification alloc] init];
n1.alertBody = [NSString stringWithFormat:@"John commented on your post"];
n1.soundName = UILocalNotificationDefaultSoundName;
n1.fireDate = [NSDate date];
[[UIApplication sharedApplication] presentLocalNotificationNow:n1];

但现在的问题是,通知只在我打开我的应用程序时出现,我可以让我的iphone在后台或锁定时出现通知吗?

我得到了解决方案!只需在我的 rails

中添加此选项参数
  options[:notification] = {}
  options[:notification][:title] = 'title'
  options[:notification][:body] = 'Calvin Sugianto vote on your post'
  options[:content_available] = true
  options[:notification][:sound] = "default"

在此代码之前

  response = fcm.send(registration_ids, options)