ios Firebase推送通知项目 [英] ios Firebase Push Notification project

查看:895
本文介绍了ios Firebase推送通知项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Firebase的新手,我正在寻找一个实施了推送通知的iOS项目,以了解Firebase推送通知的工作原理并了解它。
有人可以告诉我在哪里可以找到它吗?



谢谢!

解决方案

更新:SWIFT 3.0:



如何将您的iOS项目与Firebase集成。



为了将您的项目与Firebase集成以进行推送通知,您需要执行以下操作:


  1. 使用CocoaPods将项目与Firebase集成。打开终端并编写 cd ,然后将包含项目的文件夹拖到终端,这样就可以避免编写整个路径。


  2. 进入终端的文件夹后,写下:



    $ pod init


将在名为 Podfile 的项目中为您创建新文件


  1. 在文本编辑器中打开 Podfile 文件,并在之前添加 pod'Firebase' 结束关键字。


  2. 保存文件并返回终端并确保您仍在项目路径中。


  3. 然后在终端中编写 pod install ,这应该开始下载Firebase并将其与您的项目集成。


6.完成下载后,您应该在项目文件夹中看到一个新文件 .xcworkspace ext ension。这是您应该从现在开始打开的文件。


  1. 转到下面的链接并生成您的证书以便您可以在控制台中将其上传到Firebase项目。

https://www.mobiloud.com/help/knowledge-base/how-to-export- push-notification-certificate-p12 /


  1. 打开你的项目并导航到AppDelegate,执行以下操作;



    //导入框架

     导入Firebase 


位于应用程序顶部。


  1. 现在在应用程序中:didFinishLaunchingWithOptions:方法添加



    //使用Firebase库配置API

      FIRApp.configure()


  2. 在registerFo中rRemoteNotifications方法添加以下内容:

     设置:UIUserNotificationSettings = UIUserNotificationSettings(forTypes:[。Alert,.Badge,.Sound],类别:零)

    application.registerUserNotificationSettings(设置)

    application.registerForRemoteNotifications()


更新:SWIFT 3.0:

  UNUserNotificationCenter.current()。requestAuthorization(options:[.alert,.badge,.sound]){(授予:Bool,错误:错误?)

如果授予{

} else {

}

}


UNUserNotificationCenter.current()。delegate = self

和代表:

  func userNotificationCenter(_ center:UNUserNotificationCenter,willPresent通知:UNNotification,withCompletionHandler completionHandler:@escaping( UNNotificationPresentationOptions) - >无效){

}

func userNotificationCenter(_ center:UNUserNotificationCenter,didReceive response:UNNotificationResponse,withCompletionHandler completionHandler:@escaping() - > Void){

}




  1. 你应该将以下方法添加到AppDelegate,以便在应用程序运行时接收消息;

      func application(application: UIApplication,didReceiveRemoteNotification userInfo:[NSObject:AnyObject],fetchCompletionHandler completionHandler:(UIBackgroundFetchResult) - > Void){

    print(消息ID:\(userInfo [gcm.message_id]!) )

    }


  2. 请点击以下链接测试发送推送


https://firebase.google.com/docs/notifications/ios/console-device


I'm very new at Firebase and i'm looking for an iOS project with push notifications implemented, to look how Firebase push notifications work and learn of it. Can someone tell me where i can find it?

Thank you!

解决方案

UPDATED: SWIFT 3.0:

How to integrate your iOS project with Firebase.

In Order to integrate your project with Firebase for push notifications you need to do the following:

  1. Integrate your project with Firebase by using CocoaPods. Open Terminal and write cd and then drag the folder that contains your project to the Terminal so you avoid writing the whole path.

  2. Once you're inside the folder in Terminal, write:

    $ pod init

and new file will be created for you inside the project called Podfile

  1. Open Podfile file in your text editor and add pod 'Firebase' before the end keyword.

  2. Save the file and go back to Terminal and make sure you are still inside the project path.

  3. Then write pod install in Terminal and this should start downloading Firebase and integrating it with your project.

6.Once done downloading you should see a new file in your project folder with .xcworkspace extension. This is the file you should open from now on.

  1. go to the link below and generate your certificate in order for you to upload it to your Firebase project in the console.

https://www.mobiloud.com/help/knowledge-base/how-to-export-push-notification-certificate-p12/

  1. Open your project and navigate to AppDelegate and do the following;

    // Import framework

      import Firebase
    

on the top of your App.

  1. Now inside application:didFinishLaunchingWithOptions: method add

    // Use Firebase library to configure APIs

    FIRApp.configure()
    

  2. Inside registerForRemoteNotifications method add the following:

     let settings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
    
        application.registerUserNotificationSettings(settings)
    
        application.registerForRemoteNotifications()
    

UPDATED: SWIFT 3.0:

  UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.badge,.sound]) { (granted:Bool, error:Error?) in

            if granted {

            }else{

            }

        }


        UNUserNotificationCenter.current().delegate  = self

and for the delegate:

  func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

}

 func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

}

  1. You should add the following method to your AppDelegate in order for you to receive messages while the app is running;

    func application(application:UIApplication,didReceiveRemoteNotification userInfo: [NSObject : AnyObject],fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
    
     print("Message ID: \(userInfo["gcm.message_id"]!)")
    
     }
    

  2. Follow the link below to test sending a push

https://firebase.google.com/docs/notifications/ios/console-device

这篇关于ios Firebase推送通知项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆