ios Firebase Push Notification project

2 Solutions Collect From Internet About “ios Firebase Push Notification project”

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

There is a thing provided by any SDK, which is called Documentation. And here is the link to Firebase documentations. Follow this step by step its well explained.

Also you can find the example project for FCM(cloud messaging) from this GitHub’s repository under messaging.

During this journey if you got stuck anywhere, then post your real question(problem) here, someone can guide you through.