How to show Google play signin dialoge only once? - unity3d

I'm using Google Play Games service in my unity game and want to silently login my game so that the dialogue popup at the top shows only once.
Right now everytime I open the game that dialogue comes up. like this
And it takes around 5s for the dialog thing to complete that's why I want to do it silently so that user can directly enter to game if they have just signed in.
I've seen in some games that when we opens the game for the very first time only then that dialogue comes and on next further opening the dialogue doesn't comes and we directly enter to the game.
My code is
void Start()
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.AddOauthScope("profile")
.RequestServerAuthCode(false)
.Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
if (!PlayGamesPlatform.Instance.localUser.authenticated)
{
Debug.Log("We're not authenticated in, let's authenticate first");
PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptOnce,
(code) =>
{
if (code == SignInStatus.Success)
{
Debug.Log("We're not signed in, let's signin first");
/// Signed in! Hooray!
PlayFabClientAPI.LoginWithGoogleAccount(new LoginWithGoogleAccountRequest()
{
ServerAuthCode = PlayGamesPlatform.Instance.GetServerAuthCode(),
CreateAccount = true,
}, OnGoogleLoginSuccess, error =>
{
Debug.Log("Error " + code);
// TODO: Move to splash scene with practice mode only
});
}
else
{
/// Error signing in. We'll want to show a sign in button
}
}); /// <--- That "true" is very important!
}
else
{
Debug.Log("We're already signed in");
}
}
so the main issue is that PlayGamesPlatform.Instance.localUser.authenticated
always returns false.
Thanks!

Related

How can I keep the BarcodeScanner screen open without redirecting me to another page?

I am making an application that allows me to scan QR codes, and I managed to make the code work but my doubt is that when I scan the plugin phonegap-plugin-barcodescanner takes me out of the camera interface, what I want to do is to stay in it and show me an alert with the scanned code, and to give it ok in the alert to stay in it, to avoid being clicked to enter it.
I'm working with the plugin phonegap-plugin-barcodescanner, in ionic 3
public scanQR2() {
this._ButtonText = "Escanear";
this._barcodeScanner.scan().then((barcodeData) => {
if (barcodeData.cancelled) {
console.log("User cancelled the action!");
this._ButtonText = "Escanear";
return false;
}
console.log("Scanned successfully!");
console.log(barcodeData);
}, (err) => {
console.log(err);
});
}
I hope that the application when performing a scan stays on the same interface and does not redirect me to another page

button back to my app in the background and when you resume it starts again

I am developing an app in Xamarin.Forms, before I was trying to make a master detail page to become my MainPage when I logged in to my app, this I have already achieved. Now I have the problem that when I use the button behind the phone my app is miimiza and goes to the background which is the behavior I hope, but when I return to my app does not continue showing my master detail page, but returns to my LginPage.
It is as if my app was running twice or at least there were two instances of LoginPage existing at the same time, this is because in my LoginPage I trigger some DisplayAlert according to some messages that my page is listening through the MessaginCenter and they are they shoot twice.
Can someone tell me how I can return the same to my app on the master detail page and not restart in the strange way described?
LoginView.xaml.cs:
public partial class LogonView : ContentPage
{
LogonViewModel contexto = new LogonViewModel();
public LogonView ()
{
InitializeComponent ();
BindingContext = contexto;
MessagingCenter.Subscribe<LogonViewModel>(this, "ErrorCredentials", async (sender) =>
{
await DisplayAlert("Error", "Email or password is incorrect.", "Ok");
}
);
}
protected override void OnDisappearing()
{
base.OnDisappearing();
MessagingCenter.Unsubscribe<LogonViewModel>(this, "ErrorCredentials");
}
}
Part of my ViewModel:
if (Loged)
{
App.token = token;
Application.Current.MainPage = new RootView();
}
else
{
MessagingCenter.Send(this, "ErrorCredentials");
}
Thanks.
I hope this is in Android. All you can do is, you can override the backbuttonpressed method in MainActivity for not closing on back button pressed of the entry page. like below, you can add some conditions as well.
public override void OnBackPressed()
{
Page currentPage = Xamarin.Forms.Application.Current.MainPage.Navigation.NavigationStack.LastOrDefault();
if (currentPage != null)
{
if (currentPage.GetType().Name == "HomePage" || currentPage.GetType().Name == "LoginPage")
{
return;
}
}
base.OnBackPressed();
}
When you press the Home button, the application is paused and the
current state is saved, and finally the application is frozen in
whatever state it is. After this, when you start the app, it is
resumed from the last point it was saved with.
However, when you use the Back button, you keep traversing back in
the activity stack, closing one activity after another. in the end,
when you close the first activity that you opened, your application
exits. This is why whenever you close your application like this, it
gets restarted when you open it again.
Answer taken from this answer. The original question asks about the native Android platform, but it still applies here.
It means you have to Use Setting Plugin or save data in Application properties.
You have to add below code in App.xaml.cs file:
if (SettingClass.UserName == null)
MainPage = new LoginPage();
else
MainPage = new MasterDetailPage();
For Setting Plugin you can refer this link.

How to wait for PlayerPrefs.SetString to be saved on disk?

In my recent published mobile game I have implemented an online leaderboard. Some users ran into issues on registration process. In short words the registration is coded like this:
// coroutine
DownloadLeaderBoard () {
if (string.IsNullOrEmpty (PlayerPrefs.GetString ("USERNAME"))) {
RegisterUser();
yield break;
}
// Download and display Leaderboard
}
// coroutine
RegisterUser () {
// user has entered a valid username
PlayerPrefs.SetString("USERNAME" username);
DownloadLeaderboard();
}
So after I saved the username, I have to make sure that it's on the disk before I call DownloadLeaderboard() again! How can I achieve that and prevent that RegisterUser() is called multiple times?
if (PlayerPrefs.HasKey("USERNAME")) {
// dont't register user again
}

webworks blackberry 10 window.open twitter facebook

i am just trying to implement facebook and twitter in my Webworks App and cannot get them work together.
I am using the FaceBook-OAuth-2 and the Twitter-OAuth-1 sample and i just put both stuff together and my problem is that only the first startOAuth() opens a window in the app to login the second doesn't so if i first clicked facebook it works after when i try twitter nothing happens.
https://github.com/blackberry/BB10-WebWorks-Samples
thanks
function setClickHandlers() {
console.log('set click handlers');
var fb = document.getElementById('facebookOn');
fb.addEventListener('click', function(e) {
// if the childWindow is already open, don't allow user to click the button
if(childWindow !== null) {
return false;
}
e.preventDefault();
toast('Contacting Facebook...');
setTimeout(function() {
startOAuth();
}, 500);
});
console.log('set twitter click handlers');
var tw = document.getElementById('twitterOn');
tw.addEventListener('click', function(e) {
// if the childWindow is already open, don't allow user to click the button
if(childWindow !== null) {
return false;
}
e.preventDefault();
toast('Fetching access token...');
setTimeout(function() {
twittergetAccessToken();
}, 500);
});
}
I would start by adding some debug code in your click handler to see if that's getting called when you click the button in the first place.
If it is, then I recommended you use Web Inspector (console) to see if there are any errors. If there are, they'll show up there.
Good reference for Web Inspector here - http://developer.blackberry.com/html5/documentation/web_inspector_overview_1553586_11.html
If the click handler is not being fired then perhaps you have the wrong element ID, or the setClickHandlers function is not being executed.

Process start & end on button click

i have created an application.In that i have created a button.After clicking on the button a process get's started.Now when i press the close('X') button of the application,the application closes.I want all this to happen on a click of a button i.e When i click the button for the first time it should start the process & as soon as click the same button again the process should get closed.
Here it is. Comments are inside code.
using System.Diagnostics;
/// <summary>
/// Process started by our app
/// </summary>
Process process;
private void button1_Click(object sender, EventArgs e)
{
// Haven't been started yet or user closed it
if (process == null || process.HasExited)
{
// Do open
try
{
process = Process.Start("notepad.exe");
}
catch (Exception ex)
{
// Inform user about error
}
}
// It is started
else
{
// many a thing can go wrong here.
// Even something as simple as user closing the app himself
try
{
// Send app instruction to close itself
if (!process.CloseMainWindow())
{
// Unable to comply - has to be put to death
// Merciful people might give it a few retries
// before execution
process.Kill();
}
}
catch (Exception ex)
{
// Inform user about error
}
finally
{
// So the cycle of life can start again
process = null;
}
}
}
You can use flags that stores a true value if the application is already running i.e. if the button is pressed for the first time. Then use a simple if condition to call the respective function.