ios Firebase 推送通知项目
<p><div>
<aside class="s-notice s-notice__info post-notice js-post-notice mb16"role="status">
<div class="d-flex fd-column fw-nowrap">
<div class="d-flex fw-nowrap">
<div class="flex--item wmn0 fl1 lh-lg">
<div class="flex--item fl1 lh-lg">
<b>已结束。</b>此问题不符合 <a href="https://stackoverflow.com/help/closed-questions" rel="noreferrer noopener nofollow">Stack Overflow guidelines</a> .它目前不接受答案。
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p><strong>更新:SWIFT 3.0:</strong> </p>
<p><strong>如何将您的 iOS 项目与 Firebase 集成。</strong></p>
<p>为了将您的项目与 Firebase 集成以获取推送通知,您需要执行以下操作:</p>
<ol>
<li><p>使用 CocoaPods 将您的项目与 Firebase 集成。打开 <strong>Terminal</strong> 并写入 <strong>cd</strong>,然后将包含您的项目的文件夹拖到终端,以免写入整个路径。</p></li>
<li><p>进入终端文件夹后,输入:</p>
<p><strong>$ pod init</strong></p></li>
</ol>
<p>并且将在名为 <strong>Podfile</strong></p> 的项目中为您创建新文件
<ol 开始=“3”>
<li><p>在文本编辑器中打开 <strong>Podfile</strong> 文件,并在 <strong>end</strong> 关键字之前添加 <strong>pod 'Firebase'</strong>。</p></li>
<li><p>保存文件并返回终端并确保您仍在项目路径中。</p></li>
<li><p>然后在终端中编写 <strong>pod install</strong>,这应该会开始下载 Firebase 并将其与您的项目集成。</p></li>
</ol>
<p>6.下载完成后,您应该会在项目文件夹中看到一个带有 <strong>.xcworkspace</strong> 扩展名的新文件。这是您从现在开始应该打开的文件。</p>
<ol 开始 =“7”>
<li>转到下面的链接并生成您的证书,以便您将其上传到控制台中的 Firebase 项目。</li>
</ol>
<p> <a href="https://www.mobiloud.com/help/knowledge-base/how-to-export-push-notification-certificate-p12/" rel="noreferrer noopener nofollow">https://www.mobiloud.com/help/knowledge-base/how-to-export-push-notification-certificate-p12/</a> </p>
<ol start="8">
<li><p>打开您的项目并导航到 AppDelegate 并执行以下操作;</p>
<p>//导入框架</p>
<pre><code>import Firebase
</code></pre> </li>
</ol>
<p>在您的应用顶部。</p>
<ol start="9">
<li><p>现在在 application:didFinishLaunchingWithOptions: 方法添加</p>
<p>//使用 Firebase 库配置 API</p>
<pre><code>FIRApp.configure()
</code></pre> </li>
<li><p>在 registerForRemoteNotifications 方法中添加以下内容:</p>
<pre><code> let settings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
</code></pre> </li>
</ol>
<p><strong>更新:SWIFT 3.0:</strong> </p>
<pre><code>UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.badge,.sound]) { (granted:Bool, error:Error?) in
if granted {
}else{
}
}
UNUserNotificationCenter.current().delegate= self
</code></pre>
<p>对于代表:</p>
<pre><code>func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
}
</code></pre>
<ol start="11">
<li><p>您应该将以下方法添加到您的 AppDelegate 以便您在应用运行时接收消息;</p>
<pre><code>func application(application:UIApplication,didReceiveRemoteNotification userInfo: ,fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
print("Message ID: \(userInfo["gcm.message_id"]!)")
}
</code></pre> </li>
<li><p>点击以下链接测试发送推送</p></li>
</ol>
<p> <a href="https://firebase.google.com/docs/notifications/ios/console-device" rel="noreferrer noopener nofollow">https://firebase.google.com/docs/notifications/ios/console-device</a> </p></p>
<p style="font-size: 20px;">关于ios Firebase 推送通知项目,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/38262378/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/38262378/
</a>
</p>
页:
[1]