There exists a float var called "SessionPauseThresholdSec" in the AnalyticEventsBase class. Though I'm not exactly sure
what this class is meant to be used for (uploading analytical data?) , we do know that "SessionPauseThresholdSec" is the minimum amount of time
allowed to pass before a "session" is considered to be over. (As we see in the comments above it. Just look for it in AnalyticEventsBase.uc)
This is an iOS specific float var that is used when an app is "backgrounded". If an app is "backgrounded" for more than the "SessionPauseThresholdSec"
than that session is over.
By reducing SessionPauseThresholdSec to a very small amount (I just used 0.001f here) then when returning after that small amount of time, it will be known that the session was over.
Since the threshold is so small the session should always be over whenever the user exits the app using the home button/sleep button and returns to it.
(if a user just presses the home button, looks at other apps, but never changes app the session will NOT end. But for my uses which is for fixing an mp3 issue its fine because that case did not result in the music stopping)
So, I created a simple class with a timer which always check if the session has ever ended. If it has ended, then when the user returns, the timer will be aware because there is a IsSessionInProgress() that can be called and it will return false at that point. Then any function can be called etc. (in my case, play music again)
Once the session has been detected to end, the AnalyticEventsBase object's session will have be restarted by calling "StartSession()" again.
But yes. I could not find anyone else who has found a solution using UDK. I just made this class rather quickly and it an probably be cleaned up a bit.
Code:
class PX1_ActiveAppManager extends Actor; var AnalyticEventsBase Analytics; function PostBeginPlay() { super.PostBeginPlay(); Analytics = class'PlatformInterfaceBase'.static.GetAnalyticEventsInterface(); Analytics.SessionPauseThresholdSec = 0.001f; Analytics.StartSession(); setTimer(0.1f, true, 'checkActive'); } function checkActive() { if (Analytics != None) { if (!Analytics.IsSessionInProgress()) { WorldInfo.Game.Broadcast(self, "WAS INACTIVE!!!!"); Analytics.StartSession(); alertAppHasResumed(); } } } function alertAppHasResumed() { WorldInfo.Game.Broadcast(self, "RETURNED FROM INACTIVE STATE"); //Do Whatever Code that needs to be done } defaultproperties { //Need to know active status return even when paused bAlwaysTick = true; }
For those interested in the music issue:
If you call "mobile PauseSong" then "mobile ResumeSong" after a user returns to the app, then the background mp3 will resume where it last started. "mobile PauseSong" is needed otherwise it will not play at all for some reason.
There is an interesting left over strange occurrence when using "mobile PauseSong". When trying to replay that same song from the beginning it will "resume" from where it last ended. For some reason, even when calling "mobile StopSong" it appears ios or udk still contains that pause data.
A solution would be rather than calling PauseSong, to play a short silence.mp3 then play the desired song again. But this results in the song being restarted when returning to the app.
I prefer the PauseSong method. Also, after the first "resume bug", it will then "restart" the song over again properly after that.
It's a bit confusing, but I've had to do a lot of trial and error and this is what appears to be the case.
Anyways, hope this helps anyone that needs it.
Leave a comment: