Flutter Firebase Dynamic Link not working on new ios app install - firebase

I am trying to handle dynamic links within my flutter app and they work perfectly when the app is already installed. The link works fine regardless if the app is open or closed in the background. However when I try to use a link when the app is not installed I am properly brought to the app store, but then once I open the app from within the app store after the install completes it just opens the app and my dynamic link functionality never executes.
My dynamic link is similar to this:
https://startingxi.page.link/?link=https://url-redacted/game/gameId&apn=myapn&isi=mysi&ibi=myibi&st=new%20team%20vs%20&sd=1%20-%202&efr=1
I have tried with both efr=1 and without that.
My flutter code:
#override
void initState() {
super.initState();
initDynamicLinks();
futureInitState = initStateAsync();
}
Future<void> initDynamicLinks() async {
final PendingDynamicLinkData data = await FirebaseDynamicLinks.instance.getInitialLink();
final Uri deepLink = data?.link;
await processDeepLink(deepLink);
FirebaseDynamicLinks.instance.onLink(onSuccess: (PendingDynamicLinkData dynamicLink) async {
final Uri deepLink = dynamicLink?.link;
await processDeepLink(deepLink);
}, onError: (OnLinkErrorException e) async {
print('onLinkError');
print(e.message);
displayFlushBar('$e.message');
});
}
I have tried putting the initDynamicLinks within my futureInitState which is part of my FutureBuilder which does other async stuff at startup. Any help would be appreciated. I'm not sure how to debug this problem and this is my first ios/app dev experience so I'm not sure if there are some logs on the ios device that may help? But at the moment it seems as though I need to deploy to production and get my change live in the app store before I can test anything and that seems less than ideal. But since the dynamic link works in the other use cases I'm stumped on troubleshooting.
Thanks!

Common troubleshooting steps for issues on opening Firebase Dynamic Links after app install is to make sure that value of the ibi parameter matches the app's Bundle ID.
For Google-provided *.page.link domains: in the Capabilities tab of the app's Xcode project, Associated Domains shoudld be enabled, and the following is added in the Associated Domains list: applinks:{your_dynamic_links_domain}.
Also, verify that the AASA of your FDL https://{your_dynamic_links_domain}/apple-app-site-association contains an entry for your app. Verify "appID":"{team-id}.{bundle-id}" values are correct for your app
If these steps didn't work, it's best to reach out to Firebase Support as they have the tools to diagnose deeper into this issue.

Related

Why Isn't app.initailzation() working in my Teams Add-in OAuth flow?

I am trying to get simple auth in my Teams app working with Adobe ID (a third party Oauth provider that I use on my site).
I am following the sample here. Everything is working to authorize with the Adobe ID, but when it gets to my end authentication page like this, I get an exception thrown with the message "SDK initialization timed out." when I call await app.initialize();. The sample shown does not have the await term before app.initialize(). Is that incorrect? If I remove the await, my code later on to notify authentication of success, fails with the exception "The library has not yet been initialized".
authentication.notifySuccess("Yippee");
What do I need to do to allow app.initialize() to work?
How can the sample work if there is no await before it?
Here is the TypeScript code for my OAuth End page that is loaded after the Adobe Authentication succeeds.
import $ from "jquery";
import {app, authentication} from "#microsoft/teams-js";
startup();
async function startup(){
try{
$("#status").text("Initializing");
await app.initialize();
$("#status").text("Initialized");
console.log("notifying of success");
authentication.notifySuccess("Yippee");
}
catch(error){
handleError(error, "initializing");
}
}
function handleError(error:Error, context: string){
console.error(`💥 Error ${context}: ${error.message}`);
$("#status").text(error.message);
}
What version of the js library are you using?
There have been some changes to how app.initialize is handled depending on the version of the SDK you are using- see details here
https://learn.microsoft.com/en-us/microsoftteams/platform/tabs/how-to/using-teams-client-library?tabs=typescript%2Cmanifest-teams-toolkit#callbacks-converted-to-promises
You should be able to see this in package.json for typescript, although I think there may be other areas where you may need to update this.
Try this with the version referenced in the sample- 2.0.0 does that resolve the issue?
re: await- that just tells the application to wait until a response is returned (a success or failure) before moving on to the next line. In your case, you need the await as your next line is dependent on the value of status, but your function is async, so it won't block the execution of other async functions. You want to use await where you have other requests that must have a response on that call- like getauthtoken.

Flutter app crashing without exception when calling FacebookAuth.instance.login()

I've followed the tutorial for implementing the Facebook Login from
https://firebase.flutter.dev/docs/auth/social/
Which is the official documentation, my function is literally just:
facebookLogin() async
{
final LoginResult loginResult = await FacebookAuth.instance.login(); // final OAuthCredential facebookAuthCredential = FacebookAuthProvider.credential(loginResult.accessToken!.token);
// var credentials = await FirebaseAuth.instance.signInWithCredential(facebookAuthCredential);
}
I've commented the following function to isolate the problem.
On the console i get the following:
Performing hot reload...
Reloaded 1 of 1031 libraries in 908ms.
Lost connection to device.
And no exceptions nor errors.
Has anyone faced the same problem before?
I'm using:
flutter_facebook_auth: ^4.1.1
firebase_core: ^1.13.1
firebase_auth: ^3.3.9
In my pubspec.yaml
Is there any way to debug this problem further and find the problem?
Please ensure that you followed the setup steps one by one, and they are:
Ensure the "Facebook" sign-in provider is enabled on the Firebase Console. with the Facebook App ID and Secret set
follow the steps in the plugin (flutter_facebook_auth) documentation to ensure that both the Android & iOS Facebook SDKs have been initialized correctly
Please note that firebase flutterfire uses: flutter_facebook_auth: '^3.5.0' in their documentation and the latest version of that package 4.1.1 untill this day (3/4/2022)
It can be an issue with info.plist configuration for flutter deep-linking.
Did you setup it for your app?
https://docs.flutter.dev/development/ui/navigation/deep-linking
to be more specific you should have only one CFBundleURLTypes section in your info.plist
I had exactly the same problem. Here is how I solved.
In Info.plist, I had 2 sessions called "CFBundleURLTypes", one for Facebook Login, and another one for Google login. Apparently you can only have one CFBundleURLTypes session.
So the solution was to merge everything into a single CFBundleURLTypes session.

Flutter - Dynamic links send user to a website if not android

I am using the dynamic links plugin to create a link, I want that when user clicks on the link if her or she is not on android then he or she must be sent to a website as I have only an android app, but if on android then he must be sent to the app. How to get the desired result? there is no method in the plugin for fallback links for different os. I am creating a dynamic link through code and not in the firebase console.
according to firebase while constructing dynamic links manually we can give Other platform parameters as ofl:
ofl: The link to open on platforms besides Android and iOS. This is useful to specify a different behavior on a desktop, like displaying a full web page of the app content/payload (as specified by param link) with another dynamic link to install the app.
it also has a ifl, i.e if app is not installed on ios:
ifl: The link to open when the app isn't installed. Specify this to do something other than install your app from the App Store when the app isn't installed, such as open the mobile web version of the content, or display a promotional page for your app.
But can't find both ifl and ofl feature in the flutter firebase dynamic links plugin.
You can manually add ofl (or afl, or ifl) to the long Uri string and use it directly, or even build a short URL from it.
This code creates a DynamicLinkParameters variable parameters using the DynamicLinkParameters() constructor inside an async function, then uses it to create a short link that falls back to https://example.com on desktop:
final DynamicLinkParameters parameters = DynamicLinkParameters(
// constructor arguments
);
final Uri longLink = await parameters.buildUrl();
final ShortDynamicLink shortDynamicLink = await DynamicLinkParameters.shortenUrl(Uri.parse(longLink.toString() + "&ofl=https://example.com"));
final Uri dynamicLinkShortUrl = shortDynamicLink.shortUrl;
If i understood your problem correctly, you want to use a link if the user is on android and other if the user is on ios. That can be done importing dart:io and doing something like this:
if (Platform.isAndroid) {
// add the link to the android page
} else if (Platform.isIOS) {
// do something else
}

get History version from firebase hosting

I have site that deployed on firebase hosting site
on the site I wrote Version 3 but instead of that I want to show the deployment / release version like e925c5 that writen on the history version.
can I get history version with Rest API.? or can I define it before deployed.?
thank you
Update
I try with reading documentation and working with it, but still stuck with the authentication method,
Simple function is this, but always returned 403 response, already try with getGlobalDefaultAccount.login() and getGlobalDefaultAccount.getAccessToken() and getGlobalDefaultAccount() still not working,
const requireAuth = require('firebase-tools/lib/requireAuth')
const getGlobalDefaultAccount = require('firebase-tools/lib/auth')
const api = require('firebase-tools/lib/api')
const site = 'sarafe-testing'
requireAuth(getGlobalDefaultAccount.getAccessToken(), ['https://www.googleapis.com/auth/cloud-platform']).then(async () => {
try {
const response = await api.request('GET', `/v1beta1/sites/${site}/releases`, { auth: true, origin: api.hostingApiOrigin })
console.log(response)
} catch(e) {
console.log(e.message)
}
})
Full version
For now I just created table that hold version code (manuali update from firebase page) and make API to get the version, but this not a valid solution because is only show the latest version, some other people just open the webpage without refresh / clear cache so that one is still using the old version of webpage with latest version written,
Yes, there is a REST API that allows you to manage versions and releases for Firebase Hosting, and it has a method to get a list of versions for the site. I recommend checking out its documentation and reporting back if you get stuck while implementing the code.

Unity App Crashes When Sign-In via Play Games is Attempted

I have a problem that has been chasing me for the last few days.
I did all the necessary configuration to set up the Google Play Games sign-in method to my Unity game for Android.
However, every time I click the sign-in button the Play Games icon briefly appears at the top and the app suddenly crashes.
Analyzing the logcat, it seems there is an error on the highlighted line (last line of the 'InitializePlayGamesPlatform()' method) of the following script:
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine;
public class UserManager : MonoBehaviour
{
private Firebase.Auth.FirebaseAuth firebaseAuth;
private Firebase.Auth.FirebaseUser firebaseUser;
void Start()
{
InitializePlayGamesPlatform();
}
private void InitializePlayGamesPlatform()
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.RequestServerAuthCode(false)
.Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.Activate();
************firebaseAuth = Firebase.Auth.FirebaseAuth.DefaultInstance;************
}
public void TrySignIn()
{
UnityEngine.Social.localUser.Authenticate((bool success) =>
{
if (!success)
{
Debug.LogError("UserManager: Failed to sign in into Play Games!");
return;
}
string authCode = PlayGamesPlatform.Instance.GetServerAuthCode();
if (string.IsNullOrEmpty(authCode))
{
Debug.LogError("UserManager: Failed to get auth code!");
return;
}
Debug.LogFormat("UserManager: auth code is: {0}", authCode);
Firebase.Auth.Credential credential = Firebase.Auth.PlayGamesAuthProvider.GetCredential(authCode);
firebaseAuth.SignInWithCredentialAsync(credential).ContinueWith(task =>
{
if (task.IsCanceled)
{
Debug.LogError("UserManager: sign-in was canceled!");
return;
}
if (task.IsFaulted)
{
Debug.LogError("UserManager: error signing in!");
return;
}
firebaseUser = task.Result;
Debug.LogFormat("UserManager: user signed in successfully: {0} ({1})", firebaseUser.DisplayName, firebaseUser.UserId);
});
});
}
public void TrySignOut()
{
firebaseAuth.SignOut();
}
}
Also, there are some other messages/errors in the logcat, such as:
Failed to read Firebase options from the app's resources. Either make sure google-services.json is included in your build or specify options explicitly.
InitializationException: Firebase app creation failed.
at Firebase.FirebaseApp.CreateAndTrack (Firebase.FirebaseApp+CreateDelegate createDelegate, Firebase.FirebaseApp existingProxy) [0x000da] in Z:\tmp\tmp.txs8ldQ514\firebase\app\client\unity\proxy
at Firebase.FirebaseApp.Create () [0x00000] in Z:\tmp\tmp.txs8ldQ514\firebase\app\client\unity\proxy\FirebaseApp.cs:119
at Firebase.FirebaseApp.get_DefaultInstance () [0x0000b] in Z:\tmp\tmp.txs8ldQ514\firebase\app\client\unity\proxy\FirebaseApp.cs:94
at Firebase.Auth.FirebaseAuth.get_DefaultInstance () [0x00000] in Z:\tmp\tmp.poUq23PLco\firebase\auth\client\unity\proxy\FirebaseAuth.cs:294
I repeated every procedure from the beginning a thousand times, searched everywhere and got no results.
I have tried running an older version of GPG plugin as well, but no success at all.
I kindly ask you to help me on this - I promise to put your names on the credits in case I publish!! :)
Thanks in advance!!
A Firebase support member (#Jesus) has just helped me to figure the issue out. The workaround is directly adding the sourceset to the mainTemplate.gradle.
I had to do the following:
Go to Project Settings > Publishing Settings > Build > checkmark Custom Main Gradle Template.
It will give you the location to the mainTemplate.gradle file.
Here is an example.
Go to the given directory and open mainTemplate.gradle with a text editor.
Add the following code to the referred file, right after lintOptions:
sourceSets { main { res.srcDirs += '<full path from your root directory to google-services.xml>' } }
Also, add this array to noCompress under aaptOptions:
noCompress = ['.unity3d', '.ress', '.resource', '.obb', 'google-services.json']
In the end, the mainTemplate.gradle should look like this:
lintOptions {
abortOnError false
}
sourceSets { main { res.srcDirs += 'C:\\Users\\USERNAME\\Documents\\Unity Projects\\GAMENAME\\Assets\\Plugins\\Android\\Firebase\\res\\values\\google-services.xml' } }
aaptOptions {
noCompress = ['.unity3d', '.ress', '.resource', '.obb', 'google-services.json']
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
}
in my case i have setted prograurd mode in release setting under publish settings>minify>release . Setting this to none have fixed my issue.
That particular issue is related to the google-services.json file that should be automatically included in your build if the file exists in your Assets/ directory. Note that the process is different enough from the Android process that you probably need to ignore the Firebase Android instructions and only follow the Unity ones unless you really know what you're doing.
I'll tackle the easiest problem first. Make sure you have your google-services.json file in your Assets/ directory. I usually keep mine in Assets/Data/ (which is where I also keep things like ScriptableObjects). If you don't have it, follow the instructions on the Download Firebase config file or object help page:
Get config file for your Android app Go to your the Settings icon
Project settings in the Firebase console. In the Your apps card,
select the package name of the app for which you need a config file.
Click google-services.json. Move your config file into the module
(app-level) directory of your app. Make sure that you only have this
most recent downloaded config file in your app.
Once you have that file, you'll need to make sure that Assets/Plugins/Android/Firebase/res/values/google-services.xml gets properly generated:
The reason why this exists is that the Unity SDK does not use the Google Services Gradle Plugin - doing so would break compatibility with older versions of Unity or teams that otherwise opt out of gradle integration. This is why I strongly advise against following any of the Android specific documentation unless you're willing to do a lot of work by hand.
If you do not have google-services.xml or you want to try to regenerate it, you should navigate to Assets>External Dependency Manager>Android Resolver>Force Resolve:
If this does fix your issue, then you should make sure that you enable auto-resolution to avoid this issue in the future:
There are also a few more subtle issues that crop up. One is that "External Dependency Manager for Unity" is a rename of the "Play Services Resolver" (developers kept thinking that it was tied to Play Services - which it isn't). So check that you don't have a Assets/Play Services Resolver directory. Also, if you're using the External Dependency Manager in the Unity Package Manager, make sure that Assets/External Dependency Manager doesn't exist as well. Since you're using two plugins that ship with EDM4U, you may have some duplication (although EDM4U should be smart enough to resolve that).
If you're still running into issues, it may help to share your directory layout WRT where the External Dependency Manager, google-services.json, google-services.xml, and the Firebase and the Play Games Sign-In plugin live. Also it could be worth noting if google-services.xml makes it into an exported project (or your APK). If any of this isn't something you want to share on Stack Overflow, feel free to reach out to Firebase Support and link this SO question.
--Patrick

Resources