Can't get debug token for Firebase App Check for my Flutter iOS App - ios

So I recently started setting up app check for my existing Flutter project (for both android and iOS platforms). I've had no problem with android's "Play Integrity", got the necessary debug token, and can successfully send and retrieve data to/from firestore (app check for firestore is currently enforced for my project).
The problem is, I can not get such a debug key for my iOS app. I will list the sources I've used and what I've tried so far.
I have firebase_app_check: ^0.1.1+8 installed via pubspec.yaml
I also added pod 'FirebaseAppCheck' to my Podfile
I have the necessary initialization code in my main.dart: await FirebaseAppCheck.instance.activate(...);
For "DeviceCheck", I am using THE SAME private key that I am using
for "Sign in With Apple" (which I have implemented successfully). I
have also enabled the checkbox for DeviceCheck in the settings of
that private key (in Apple Developer).
For my App ID (Apple Developer > Identifiers > App IDs), I have also
enabled the checkbox for "App Attest".
I have put "-FIRDebugEnabled" as an argument passed on launch in
XCode > Product > Scheme > Edit Scheme.
I always uninstall my app from my iOS simulator (iOS 16.2) or real device (iOS 16.1.2),
before trying again, because I have read across multiple forums that
the debug token only gets printed to the output the first time you
run your app.
I have also added these 4 lines of code in my AppDelegate.swift from here:
#if DEBUG
let providerFactory = AppCheckDebugProviderFactory()
AppCheck.setAppCheckProviderFactory(providerFactory)
#endif
Official firebase docs "iOS+ (App Attest)":
I have NOT copied ANY code from this page of the official docs, as I assume it's for native iOS apps only, and not for flutter, and I don't know where exactly I would have to put that code. I have only added the pod dependency and run pod install.
I don't have a .entitlements file.
So after all those steps, I'm apparently supposed to expect to find a debug token in my run output, as in:
Yet the only relevant output I can find is the following:
Runner[72719:33546579] 10.3.0 - [FirebaseFirestore][I-FST000001] AppCheck failed: 'The operation couldn’t be completed. (com.apple.devicecheck.error error 1.)'
If it matters:
I have NOT YET uploaded my iOS app to apple developer, app store connect or whatever (I'm not yet familiar with the process of publishing to the app store).
Neither have I uploaded my android app to Google Play console or created an app there (for this project).
Don't tell me anything about firestore rules. I already had that set up long ago, and everything worked just fine before I started integrating App Check.
Don't recommend any 3rd party plugins to me, I will only use official ones.

The firebase documentation says:
Tip: Confirm in your Xcode project's build settings that it passes the DEBUG flag to the Swift compiler
Try removing the '#if DEBUG' and '#endif' and run the app.
If it works, it mean you have missed that step
I was not able to find that build setting, so i just removed those lines from the AppDelegate, but i need to keep in mind to remove the other 2 lines while building the release mode

See this answer on the flutterfire Github issues page. Basically, call setAppCheckProviderFactory before GeneratedPluginRegistrant.register(with: self) in the app delegate file. I was investigating the same issue and it fixed it for me (the debug token was instantly printed out in Xcode's debug output). Hope it helps you as well!

Related

Crashlytics report can be generated only after re run the app

I just implemented Fabric Crashlytics tool to my Xcode project via Swift Package Dependencies.
All works good if I enable Google Analytic on a step when I create an app, without this step I did not received crash reports, so I switched to the app with Google Analytic enabled.
I've tested crash button from the link:
One comment that I don't like from there
"After your app crashes, run it again from Xcode so that your app can
send the crash report to Firebase."
Does it mean that user has to reopen app to send crash report? For example if a user download an app from the App Store and then somehow the app is crashed. Does mean that reopening app required for sending that crash? And if the user will not open the app it means I lost this crash report? I understand that on live store there is no option to re run it form Xcode, but reopening seems a require step.
I suppose the crash report should work different a bit by sending issue details right after a crash, I may be wrong here.
Also when I set everything via Swift Package Dependencies looks like I don't have an option to upload dSYM via this option
/path/to/pods/directory/FirebaseCrashlytics/upload-symbols -gsp /path/to/GoogleService-Info.plist -p ios /path/to/dSYMs
Does this mean I need to pull Fabric and Crashlytics from CocoaPods?
I've switched off bitcode at the moment and looks like all is works automatically but not sure it is good idea for long perspective.
Yes, crashes will be uploaded when restarting the app after it crashes. As far as I know, this is because the SDK may not have enough time to actually send the report when the crash happens.
If you are using Swift Package Manager, you still have that option.
This is the command:
"${BUILD_DIR%/Build/*}/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run"
If the app has bitcode enabled, then you'll need to download the dSYMs from the App Store and upload them manually.
Lastly, Fabric is now deprecated so don't download it. You don't need to use Cocoapods if you are already integrated Crashlytics with SPM.

Why does my Flutter app crash at startup on iOS?

I'm trying to build a simple app using Flutter for iOS and Android, but the app crashes on startup when I try to run it on an iPhone (Android runs fine). I don't have a mac, so I'm using Codemagic to compile a release build and deploy to TestFlight, then installing on an iPhone from there. Apple only shows their crash logs in Xcode as far as I can tell (nothing in App Store Connect online?), and since I don't have a mac, I can't see those. Any thoughts as to what I might be running into, or what information I can gather to debug the problem?
Thanks!
Edit: I've been digging around some more and it looks like the crash is related to the Firebase dependencies. If I create the Flutter demo project (flutter create ), it runs fine on iOS. However if I then add Firebase packages to pubspec.yaml, and manually add GoogleServices-info.plist, the app crashes on startup. (I'm not adding any code that uses Firebase yet.) GoogleServices-info.plist is supposed to be added with Xcode, but since I don't have Xcode or a mac, that makes it tough. The second answer to this question gives a suggestion: Where to save GoogleService-Info.plist in Flutter without Xcode?
I tried making those changes but got the same result. Anybody have any recommendations for adding Firebase without a mac?
Ok, so here's what happened. Originally the app crashed on iOS because there were issues with the GoogleServices-info.plist file (probably). There were no error messages, so I didn't know where to look. I finally just went back to the simple demo app and started layering things back in to isolate the issue. The demo app would build and run on iOS with no problems, but when I added the Firebase dependencies (as a group), it failed. I had added the GoogleServices-info.plist file manually (outside of Xcode) and adjusted the references in ios/Runner.xcodeproj/project.pbxproj using a text editor, but that didn't do the trick.
At this point I finally broke down and got a MacBook. Debugging on the Mac, I could now see that the app crashed in debug mode on the emulator as well as when in release mode on a device, but still no helpful error messages. I added the GoogleServices-info.plist file using Xcode, so at least that piece was correct, but the app still crashed immediately. Going through the documentation, I realized that when I made the sample app, I had forgotten to add the app ID in the info.plist file for AdMob. At this point it was just AdMob causing the crash, not the other Firebase dependencies. I added that back in and things ran fine. I wish I had looked at that a month ago. Ugh.
Thanks #Mikhail Tokharev and #season for taking a stab at such a vague question. I wish I had more detail to share initially, but I didn't know enough yet to know what could be going wrong.
TL;DR
Just get a Mac. Trying to debug through Codemagic won't work.
For Firebase, be sure you actually add your GoogleServices-info.plist file through Xcode. Trying to add it manually and hack the project.pbxproj file probably won't work (this a practical recommendation, I didn't prove this conclusively).
https://firebase.google.com/docs/flutter/setup?platform=ios#add-config-file
For AdMob, be sure to add your application ID to the info.plist. https://pub.dev/packages/firebase_admob
I've been facing this error since the last few days and I happen to solve it today. So, I would like to share it with anyone facing startup error after connecting their iOS app to firebase.
I had followed all the steps while setting up a new iOS app with firebase and this was what exactly caused the error, in my case. If you have placed import 'Firebase' and Firebase.configure() in your AppDelegate.swift, then remove it and run your app again. I removed those two lines and it worked fine. Test it with Cloud Firestore (just make a button write something to your cloud firestore) and make sure you add await Firebase.initializeApp(); as well when the button is pressed.
I did all of those steps and it worked fine with me.
P.S. I did it with android studio in a Mac.
For any newbies out there like me, make sure registering firebase is before GeneratedPluginRegistrant in your ios/Runner/AppDelegate.swift file.
// This works without crashes, FirebaseApp.configure() after GeneratedPluginRegistrant crashes
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
i had the same issue and i have fixed it as i was new to ios deployment i forgot to add capabilities which indeed crashed my app in testflight ...so please be sure you have added required capabilities in signing and capability tab in xcode
use terminal to run the app.
run this command
flutter run --release
For iOS: In our case this happened because of Facebook plugin update.
Previous version: flutter_facebook_auth: ^3.5.1
New Version: flutter_facebook_auth: ^4.3.3
We were missing FacebookClientToken in Info.plist file. So after adding that it worked.
<key>FacebookClientToken</key>
<string>$(FACEBOOK_CLIENT_TOKEN)</string>
most probably you've faced with next Flutter issue https://github.com/flutter/flutter/issues/54707
I had the same problem and solved it as below :
In the folder of flutter sdk,
I did git pull then run the app again and it was solved .
If you using Google Firebase library in flutter app
Make sure use FirebaseApp.configure() before GeneratedPluginRegistrant.register(with: self) in AppDelegate.swift file.
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)

iOS Firebase + Fabric Beta Crashylitics Not Reporting Issue

I've just recently installed Fabric to a project which already had Firebase installed and suddenly Crashyltics has stopped working. It's not included within the 'Fabric.with([])' call on AppDelegate.swift but I wondered if Fabric and Firebase were cancelling out Crashyltics. I'm using Fabric for it's Beta option and everything else is inside Firebase.
I can force a crash inside the app - But not getting anything reported in either Dashboard.
My run Script Phase is also correct.
My Debug is DWARF with DYSIM.
Cleared derived data etc.
Firebase is called after Fabric inside AppDelegate.
Thanks
I think that you have to link your firebase and fabric apps.
Go to https://fabric.io/firebase_migration/status, click on link apps and select the apps to link (the one on fabric and the corresponding app on firebase)
Do you upload your dSYM to Firebase/Crashlytics? If not it can be the issue.

Can't run Lister app sample code (Swift) from Apple's website

I tried to download and run the Lister app sample code which was presented at WWDC for the session 406: Integrating Swift With Objective-C. (I am running XCode 6.1 on Yosemite and this is the most updated version of the Lister app from the sample code page in Apple).
https://developer.apple.com/library/ios/samplecode/Lister/Introduction/Intro.html
However I was unable to run the app in XCode which are best show in the attached screenshot.
The app doesn't have the Run and Stop buttons enabled. They are greyed out. Never had this before for any other app.
The icons for the Lister app is not showing. Instead there is this new Settings-like icon which I have never seen and have no idea what it means.
There is a ReadMe.txt file in the project that you downloaded. Have you read it because I had the same problem and by reading it, my problems were solved.
Regards
The QuickStart guide included in the project gives the key setting to change in the Build Settings to enable iCloud.
In the User-Defined section, double-click on com.example.apple-
samplecode to edit the LISTER_BUNDLE_PREFIX value.
Change this prefix to a globally unique reverse DNS string for your own
organization’s name, such as com.somecompany.lister.

Fails to distribute my app: "Your app contains non-public API usage."

After I fixed some bugs and refactored my project which has been release on App Store, it fails to distribute. The Xcode shows the following error message:
Your app contains non-public API usage. Please review the errors, correct them, and resubmit your application.
The app references non-public symbols in Payload/XXX.app/XXX: UICreateCGImageFromIOSurface
XXX is the app name.
I've search the entire project, and didn't find any this keyword (UICreateCGImageFromIOSurface). How can I fix this?
Remove Reveal.framework from your project. This should not be linked in release mode of your binary.
You app contains code not only from sources, but from all statically linked libraries. You have to check all of those for containing private call. Looks like at least Reveal library contains it.
Double check any third-party libraries you are using in your project
I was facing the issue and after checking my pods file, I found that Look Back - Framwork which is available for debug builds only as for as I know. So removing that fixed the issue. Successfully submitted app through Xcode 6.1 for Apple Testflight beta testing :)
Never ship an app linked against the Reveal library. Reveal exposes
your app to deep introspection and will likely cause your app to be
rejected by the Apple review team. Reveal is intended for internal
development and debugging purposes only.
The Reveal service will stop automatically while the iOS host app is
not the frontmost app. It will automatically start again when the app
is re-opened.
Reveal supports inspection of applications compiled against iOS 6 and
later. The iOS Deployment Target build setting must also be 'iOS 6.0'
or later. You may see link errors if this is not the case.
Reveal uses Bonjour to connect with the running iOS application. If
you are running the iOS application on a device, it will need to be
on the same network as the Reveal Mac app to be able to connect with
it. If you have any problems connecting to your application check
your firewall and proxy setting to ensure they are not blocking
communications.
Find out more...
cordova plugin rm cordova-plugin-ionic-webview
cordova plugin add cordova-plugin-ionic-webview#4.1.0

Resources