Detecting an incoming call in my Unity app - unity3d

I am trying to make my game pause on incoming phone call. I am wondering if any of this functions which I used can do this. I have used them in my source code but none of them worked.
void OnApplicationPause(bool paused)
{
if (paused == true)
{
if (!isPaused)
PauseResume(true);
}
}
void OnApplicationFocus(bool hasFocus)
{
if (hasFocus == false)
{
if (!isPaused)
PauseResume(true);
}
}
Also i had found Application.runInBackground() but it is mentioned in documentation that "Note: This property is ignored on Android and iOS".

In iOS and Android, OnApplicationPause(...) is expected to be called. This user had the same issue: https://forum.unity.com/threads/onapplicationpause-not-being-called-in-ios-build.455426/
His answer was:
Apparently, it was not working because I had 'Behaviour in Background' set to Custom instead of Suspend...

Related

Unity3D firebase AUTH not working on ANDROID fierbase doesnt connect or something

in editor work fine. i am trying to add my project fierbase and in work. but when i start test at android login window dont react. i am trying to do this
Unity3D firebase AUTH not working on ANDROID
public class FirebaseINIT : MonoBehaviour
{
public static bool firebaseReady;
void Start()
{
CheckIfReady();
}
void Update()
{
if(firebaseReady == true)
{
SceneManager.LoadScene("LoginScene");
}
}
public static void CheckIfReady()
{
Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
Firebase.DependencyStatus dependencyStatus = task.Result;
if (dependencyStatus == Firebase.DependencyStatus.Available)
{
Firebase.FirebaseApp app = Firebase.FirebaseApp.DefaultInstance;
firebaseReady = true;
Debug.Log("Firebase is ready for use.");
}
else
{
firebaseReady = false;
UnityEngine.Debug.LogError(System.String.Format(
"Could not resolve all Firebase dependencies: {0}", dependencyStatus));
}
});
}
}
but not loaded next scene. and i am confused why this happen, i cant do next because dont understand problem. May this will be from android resolve? Because in order to build the project, I must remove the Resolved libraries.
otherwise if I don't remove assets=> Android=> resolve libraries then I will get the following errors
Configure project :launcher
WARNING: The option setting 'android.enableR8=false' is deprecated.
Execution failed for task ':launcher:processReleaseResources'.
A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
Android resource linking failed
the project has an additional plugin for advertising appodeal + admob at least the direction of movement of the study of the issue
and i am integrate this first time i am not sure i am at the right way

Flutter Signalr Listener is not connected in 2nd screen after migrated to null safety stable version

Chatting was working perfectly before migrating to null safety using signalr. But after migrating It is not working in chatting part.
Scenario is like there are 2 screens where I am using signalr.
1)Chatlist.
2)Chatting with person.
listener in Chatlist is perfect but in 2nd screen it is not working(Just worked when I installed and run for the 1st time). Weird issue.
All was working in old. I am using bloc for statemanagement and also migrated to yield to emit.
Piece of code is like:
void listenOnMessageReceived(
HubConnection hubConnection,
Function(Message? chatMessageReceive) onMessageReceived,
) {
final SocketResponseCallBack chatMessageReceived =
(response) => onMessageReceived(Message.fromJson(response));
final hubMethod = HubMethod(
CHAT_RECEIVED_MESSAGE_METHOD_NAME,
SignalRHelper.toSocketFunction(
CHAT_RECEIVED_MESSAGE_METHOD_NAME, chatMessageReceived));
bool exists = listenOnHubMethod.any((method) => method.methodName == CHAT_RECEIVED_MESSAGE_METHOD_NAME);
if(exists) {
listenOnHubMethod.removeWhere((element) =>
element.methodName == CHAT_RECEIVED_MESSAGE_METHOD_NAME);
SignalRHelper(hubConnection: hubConnection).on(
hubMethod.methodName,
hubMethod.methodFunction,
);
listenOnHubMethod.add(hubMethod);
}else{
SignalRHelper(hubConnection: hubConnection).on(
hubMethod.methodName,
hubMethod.methodFunction,
);
listenOnHubMethod.add(hubMethod);
}
}
I am having 2 types of above code in different screens. but it is working in only 1 screen and not listening in 2nd screen.
here is a piece of signalr listener code:
static MethodInvocationFunc toSocketFunction(
String methodName, SocketResponseCallBack responseCallBack) {
return (arguments) {
try {
if (arguments!.isEmpty) {
throw SocketEmptyResponseException(methodName);
}
final response = arguments.first;
responseCallBack(response);
} on FormatException {
throw SocketResponseException(methodName);
}
};
}
Is there any limitations in migration of stable version or anything else. Every help is appreciable.
Thank you.
Do not use signalR, on IOS it will be impossible to run listener on background or when app is closed and you will miss messages. Use FCM.

How to display Unity WebGL template in full screen after loaded [duplicate]

Task at hand is to add support for fullscreen mode to an WebGL application written in Dart.
canvas.requestFullscreen() works for simple test cases, but fails on the full app.
Please point out the way to tell what is preventing the browser from switching to fullscreen.
The code is:
void trapFullscreenError() {
document.onFullscreenError.listen((e) {
log("fullscreenerror: $e");
});
}
void toggleFullscreen(CanvasElement c) {
log(
"fullscreenSupport=${document.fullscreenEnabled} fullscreenElement=${document.fullscreenElement}"
);
if (document.fullscreenElement != null) {
log("exiting fullscreen");
document.exitFullscreen();
} else {
log("requesting fullscreen");
c.requestFullscreen();
}
}
In Chrome that code results in:
fullscreenSupport=true fullscreenElement=null
requesting fullscreen
fullscreenerror: Instance of 'Event'
Dartium debugger shows these fields:
Event [id=4]
_selector null
bubbles true
cancelable false
clipboardData null
currentTarget #document [id=5]
defaultPrevented false
eventPhase 3
hashCode 234642739
path NodeList[6] [id=6]
target canvas#main_canvas [id=7]
timeStamp 1398779450832
type "webkitfullscreenerror"
For security reasons requestFullscreen can only be called in an event handler of a keyboard or click event.
see also Javascript request fullscreen is unreliable

Chartboost with Swift - Interstitial: prefetch if NOT complete. wait... but no ad?

I am trying to integrate Chartboost ads in Swift into my project and have followed the tutorial verbatim:
https://answers.chartboost.com/hc/en-us/articles/205853276
Everything is imported and in App delegate I have:
Chartboost.startWithAppId(//stuff)
Chartboost.setShouldRequestInterstitialsInFirstSession(false)
Chartboost.cacheMoreApps(CBLocationHomeScreen)
//Chartboost
class func showChartboostAds()
{
Chartboost.showInterstitial(CBLocationHomeScreen);
}
func didFailToLoadInterstitial(location :String!, withError error: CBLoadError)
{
}
func didDismissInterstitial(location :String! )
{
if(location == CBLocationHomeScreen)
{
Chartboost.cacheInterstitial(CBLocationMainMenu)
}
else if(location == CBLocationMainMenu)
{
Chartboost.cacheInterstitial(CBLocationGameOver)
}
else if(location == CBLocationGameOver)
{
Chartboost.cacheInterstitial(CBLocationLevelComplete)
}
else if(location == CBLocationLevelComplete)
{
Chartboost.cacheInterstitial(CBLocationHomeScreen)
}
}
Then in my main view controlleR:
AppDelegate.showChartboostAds()
I have my app in test mode in the dashboard and am running on a real device but I just get Interstitial: prefetch if NOT complete. wait... in the console.
Why won't it show any ads?
Just an aside, the reason this solution works is because of the prefetch method. It seems when you call the ad the Chartboost prefetch isn't completing on time, which is causing the show call to fail.
Chartboost does have a delegate method that will give you the all-clear when prefetch completes, that may be worth a look: - (void)didPrefetchVideos;
Here's a link to the rest of the page.
Hope this helps.
I think you're trying to show the AD to quickly. Try delaying the AD, that solved it for me.

WP: What callback to be used when page is loaded from app launching

Inside MainpPage.xaml.cs, what callback can be used so that I know it is coming from launching the App but not coming from other page? I know that there is Application_Launching in App.xaml.cs. But if I place below code there, exception is thrown somewhere. If I put in Loaded callback, I can't distinguish if it is called from App launching from navigated from other page.
if (MediaPlayer.State == MediaState.Playing)
{
MediaPlayer.Pause();
}
I would like to stop any existing playing music after entering my app.
Thanks
In you App.xaml:
public void TryStopAllMusic()
{
if (MediaPlayer!=null && MediaPlayer.GameHasControl)
{
MediaPlayer.Stop(); //stop to clear any existing music
}
}
In the constructor, under InitializeComponent() of your MainPage.xaml.cs:
public MainPage()
{
InitializeComponent();
(Application.Current as App).TryStopAllMusic();
}
That's all.