<分区>
我是 Firebase 的新手,我正在寻找一个实现了推送通知的 iOS 项目,以了解 Firebase 推送通知的工作原理并了解它。 谁能告诉我在哪里可以找到它?
谢谢!
<分区>
我是 Firebase 的新手,我正在寻找一个实现了推送通知的 iOS 项目,以了解 Firebase 推送通知的工作原理并了解它。 谁能告诉我在哪里可以找到它?
谢谢!
最佳答案
更新:SWIFT 3.0:
如何将您的 iOS 项目与 Firebase 集成。
为了将您的项目与 Firebase 集成以获取推送通知,您需要执行以下操作:
使用 CocoaPods 将您的项目与 Firebase 集成。打开 Terminal 并写入 cd,然后将包含您的项目的文件夹拖到 Terminal,这样就可以避免写入整个路径。
进入终端中的文件夹后,写:
$ pod 初始化
并且将在名为 Podfile
的项目中为您创建新文件在文本编辑器中打开 Podfile 文件并在 end 关键字前添加 pod 'Firebase'。
保存文件并返回终端并确保您仍在项目路径中。
然后在终端中编写 pod install,这应该会开始下载 Firebase 并将其与您的项目集成。
6.下载完成后,您应该会在项目文件夹中看到一个扩展名为.xcworkspace 的新文件。这是您从现在开始应该打开的文件。
https://www.mobiloud.com/help/knowledge-base/how-to-export-push-notification-certificate-p12/
打开您的项目并导航到 AppDelegate 并执行以下操作;
//导入框架
import Firebase
在您应用的顶部。
现在在 application:didFinishLaunchingWithOptions: 方法中添加
//使用 Firebase 库配置 API
FIRApp.configure()
在 registerForRemoteNotifications 方法中添加以下内容:
let settings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
更新:SWIFT 3.0:
UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.badge,.sound]) { (granted:Bool, error:Error?) in
if granted {
}else{
}
}
UNUserNotificationCenter.current().delegate = self
对于代表:
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
}
您应该将以下方法添加到您的 AppDelegate 中,以便您在应用程序运行时接收消息;
func application(application:UIApplication,didReceiveRemoteNotification userInfo: [NSObject : AnyObject],fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
print("Message ID: \(userInfo["gcm.message_id"]!)")
}
按照下面的链接测试发送推送
https://firebase.google.com/docs/notifications/ios/console-device
关于ios Firebase 推送通知项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38262378/
相关文章:
iphone - 在不访问源服务器的情况下实现 Apple 推送通知
ios - 根据 API 的结果选择 Tableview 单元格
firebase - 在本地运行 Firebase 云功能?
android - 获取谷歌广告 ID Xamarin 时出错
android - 仅在应用程序端将 Google Cloud Messaging 更新为最新的 gms.gcm.GoogleCloudMessaging 是否可以?
objective-c - 在 iOS5/Objective-C 中更改来自 main.m 的图像