Flutter가 Firebase 푸시를 통합할 때 발생하는 Pitpoint

배경, 이거 할때 플러터 파이어베이스 통합검색 결과 찾아보니 몇 문장만에 설정이 완료되더라구요 막상 해보니 함정이 많더군요 정식 프로세스는 누구나 쓸 수 있습니다 , 그러나 중요한 함정은 모두가 관심을 가져야 합니다. 그래서 이 글을 쓰게 되었는데, 이 글이 저처럼 많은 함정에 빠진 친구들에게 도움이 되었으면 좋겠습니다.

하나: Android Firebase 구성

1: Firebase 콘솔로 이동하여 계정을 신청하고 애플리케이션을 만들고 google-services.json 파일을 다운로드하여 android 프로젝트의 app/ 디렉터리에 넣습니다.

2: gradle 파일 구성 두 개의 gradle 파일 중 하나는 프로젝트의 gradle 파일이고 다른 하나는 앱의 gradle 파일입니다 여기서는 gradle의 역할을 소개하지 않겠습니다. gradle의 공식 웹 사이트에.

Project-level build.gradle (<project>/build.gradle):
// 配置第三方插件相关
buildscript {
  // 指明下面的插件去哪里下载,这里是到google仓库和maven仓库去下载,它是按照顺序的,如果google下载到了就不会到maven仓库里面下载了
  repositories {
    // Make sure that you have the following two repositories
    google()  // Google's Maven repository

    mavenCentral()  // Maven Central repository

  }
  // 插件的依赖
  dependencies {
    ...
    // Add the dependency for the Google services Gradle plugin
    classpath 'com.google.gms:google-services:4.3.13'

  }
}

allprojects {
  ...
  repositories {
    // Make sure that you have the following two repositories
    google()  // Google's Maven repository

    mavenCentral()  // Maven Central repository

  }
}

공식 웹사이트에서 제공하는 app/build.gradle 솔루션은 사용하기 쉽지 않습니다. 다음은 공식 firebase입니다. 배치 위치가 매우 모호하고 개인 테스트에서 다양한 오류가 보고됩니다. .

plugins {
  id 'com.android.application'

  // Add the Google services Gradle plugin
  id 'com.google.gms.google-services'

  ...
}

dependencies {
  // Import the Firebase BoM
  implementation platform('com.google.firebase:firebase-bom:30.3.2')


  // TODO: Add the dependencies for Firebase products you want to use
  // When using the BoM, don't specify versions in Firebase dependencies
  implementation 'com.google.firebase:firebase-analytics'


  // Add the dependencies for any other desired Firebase products
  // https://firebase.google.com/docs/android/setup#available-libraries
}

결국 이 웹사이트 firebase_flutter가  저를 구했고 성공적으로 상륙하는 데 도움을 주었습니다. 아래에 올바른 구성을 붙여넣으십시오.

android/app/build.gradle
apply plugin: 'com.google.gms.google-services'

이 짧은 문장만으로도 멋집니다. 그리고 flutter 프로젝트인 firebase_core와 firebase_messaging을 소개합니다.

 3: 코드에서 Firebase 초기화

Firebase.initializeApp().then((value) async {
    print("firebase init over");
    String? token = await FirebaseMessaging.instance.getToken();
    print("token is $token");
    if(token != null && token.isNotEmpty) {
        // 将token上传到后端,让后端控制发送推送通知
    }
})

이 시점에서 android에 firebase 통합이 완료되었습니다.

2: IOS 측의 Firebase 구성, 이 단계는 나에게 매우 힘듭니다. 실제로 한 번에 한 단계씩 진행됩니다!

1: 여전히 Google-Services.plist 파일을 다운로드합니다.

2: Firebase 구성

먼저 firebase 공식 홈페이지를 살펴보겠습니다.

몇 문장이면 끝이라 아주 간단하게 생각하고 따라해봤는데 xcode 리포트로는 안찾아지고 네트워크 문제인지 확인했는데 아니어서 ios 파일로 잘라서 포드 설치를 추가했지만 GoogleUitls Yunyun에 의존하는 FirebaseCore로 오류가 보고되어 인터넷에서 문제에 대한 실제 해결책을 찾았습니다.

오류:

[!] 다음 Swift 포드는 아직 정적 라이브러리로 통합할 수 없습니다.

Swift 포드는  모듈을 정의하지 않는 FirebaseCoreInternal-library 에 의존합니다  . GoogleUtilities-library모듈 맵을 생성하는 대상(정적 라이브러리로 빌드할 때 Swift에서 가져오는 데 필요함)을 선택하려면  use_modular_headers! Podfile에서 전역으로 설정하거나  :modular_headers => true 특정 종속성을 지정할 수 있습니다.

솔루션: Podfile 수정

 platform :ios, '12.4'
  ...
  ...
  
  pod 'Firebase', :modular_headers => true
  pod 'FirebaseCoreInternal', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => true
  #....add any library need headers

 연결 주소: 해결 방법

공식홈페이지에서 공식홈페이지 방법을 보면  -쓰레기

 최악은 말할 것도 없고  

:modular_headers => true

 3: IOS는 알림을 위해 구성해야 하는 인증서를 푸시한 다음 .p8 파일을 다운로드하고 firebase 구성 백그라운드에 업로드하여 성공하려고 합니다. 그렇지 않으면 apns-string이 인식되지 않는다고 보고되며 푸시를 추가해야 합니다. 프로젝트 위치의 설정

추천

출처blog.csdn.net/lck8989/article/details/126376104