Additional iOS Script Triggers

We have some additional script triggers for iOS to use in your FileMaker iOS app:

  • Did Become Active
    Triggered when the app becomes active.
  • Did Enter Background
    Triggered when the app enters the background.
  • Did Receive Memory Warning
    The app receives a warning from the operating system about low memory availability.
  • Significant time change
    The system posts this notification when, for example, there’s a change to a new day (midnight), a carrier time update, or a change to, or from, daylight savings time. The notification doesn’t contain a user info dictionary.
  • Will enter foreground
    Triggered shortly before an app leaves the background state on its way to becoming the active app.
  • Will resign active
    Triggered when the app is no longer active and loses focus.

And since scripts run later, we also provide evaluation of expressions available to run directly. This may include Let() statements for multiple statements together.

Set Variable [ $r ; Value: MBS( "Trace") ] 
#
Set Variable [ $r ; Value: MBS( "iOSApp.SetDidBecomeActiveEvaluate"; "MBS(\"Log\"; \"inside DidBecomeActiveEvaluate\")" ) ] 
Set Variable [ $r ; Value: MBS( "iOSApp.SetDidBecomeActiveScript"; Get(FileName); "ScriptTrigger"; "inside DidBecomeActiveScript") ] 
# 
Set Variable [ $r ; Value: MBS( "iOSApp.SetDidEnterBackgroundEvaluate"; "MBS(\"Log\"; \"inside DidEnterBackgroundEvaluate\")" ) ] 
Set Variable [ $r ; Value: MBS( "iOSApp.SetDidEnterBackgroundScript"; Get(FileName); "ScriptTrigger"; "inside DidEnterBackgroundScript") ] 
# 
Set Variable [ $r ; Value: MBS( "iOSApp.SetDidReceiveMemoryWarningEvaluate"; "MBS(\"Log\"; \"inside DidReceiveMemoryWarningEvaluate\")" ) ] 
Set Variable [ $r ; Value: MBS( "iOSApp.SetDidReceiveMemoryWarningScript"; Get(FileName); "ScriptTrigger"; "inside DidReceiveMemoryWarningScript") ] 
# 
Set Variable [ $r ; Value: MBS( "iOSApp.SetSignificantTimeChangeEvaluate"; "MBS(\"Log\"; \"inside SignificantTimeChangeEvaluate\")" ) ] 
Set Variable [ $r ; Value: MBS( "iOSApp.SetSignificantTimeChangeScript"; Get(FileName); "ScriptTrigger"; "inside SignificantTimeChangeScript") ] 
# 
Set Variable [ $r ; Value: MBS( "iOSApp.SetWillEnterForegroundEvaluate"; "MBS(\"Log\"; \"inside WillEnterForegroundEvaluate\")" ) ] 
Set Variable [ $r ; Value: MBS( "iOSApp.SetWillEnterForegroundScript"; Get(FileName); "ScriptTrigger"; "inside WillEnterForegroundScript") ] 
# 
Set Variable [ $r ; Value: MBS( "iOSApp.SetWillResignActiveEvaluate"; "MBS(\"Log\"; \"inside WillResignActiveEvaluate\")" ) ] 
Set Variable [ $r ; Value: MBS( "iOSApp.SetWillResignActiveScript"; Get(FileName); "ScriptTrigger"; "inside WillResignActiveScript") ] 

Please use Trace function, at least for simulator. In Xcode you see the messages in the console output on the bottom right side of the project window (with debugger left of that). You can always query MBS( "IsIOSSimulator" ) to know whether you are in the simulator. The trace will log evaluate and thus show error codes when you run invalid expressions. Finally if you run scripts and fmplugin extended privilege is there and not allowed, you may see an error message around permission denied.

The ScriptTrigger script is simply and logs the script name and the script parameter, so it appears in the Trace:

Set Variable [ $r ; Value: MBS("Log"; Get(ScriptName) & " called with " & Get(ScriptParameter)) ]

And now we simulate a memory warning and we see the evaluate runs first and then the script is triggered:

10:01:08.033461 Evaluate "MBS("Log"; "inside DidReceiveMemoryWarningEvaluate")"
10:01:08.033710 Current file: "PlaceHolder". User "iPhone 14 Pro" on host "MyMacM1.local"
10:01:08.034080 inside DidReceiveMemoryWarningEvaluate
10:01:08.034313 Result: 0 (No error)
10:01:08.034563 Start Script "ScriptTrigger" in file "PlaceHolder" with control Pause
10:01:08.034627 Parameter: "inside DidReceiveMemoryWarningScript"
10:01:08.034703 Current file: "PlaceHolder". User "iPhone 14 Pro" on host "MyMacM1.local"
10:01:08.035459 Result: 0 (No error)
10:01:08.037281 ScriptTrigger called with inside DidReceiveMemoryWarningScript

In the trace log in Xcode, we see the Evaluate text logged and the current file and script listed as part of the trace messages. This helps us to see where a MBS Plugin function is called.

Now we put the app in background:

10:01:25.325874 Evaluate "MBS("Log"; "inside WillResignActiveEvaluate")"
10:01:25.326032 Current file: "PlaceHolder". User "iPhone 14 Pro" on host "MyMacM1.local"
10:01:25.326289 inside WillResignActiveEvaluate
10:01:25.326437 Result: 0 (No error)
10:01:25.326650 Start Script "ScriptTrigger" in file "PlaceHolder" with control Pause
10:01:25.326719 Parameter: "inside WillResignActiveScript"
10:01:25.326784 Current file: "PlaceHolder". User "iPhone 14 Pro" on host "MyMacM1.local"
10:01:25.326978 Result: 0 (No error)
10:01:25.328220 ScriptTrigger called with inside WillResignActiveScript
10:01:25.914808 Evaluate "MBS("Log"; "inside DidEnterBackgroundEvaluate")"
10:01:25.914927 Current file: "PlaceHolder". User "iPhone 14 Pro" on host "MyMacM1.local"
10:01:25.915225 inside DidEnterBackgroundEvaluate
10:01:25.915525 Result: 0 (No error)
10:01:25.915868 Start Script "ScriptTrigger" in file "PlaceHolder" with control Pause
10:01:25.915941 Parameter: "inside DidEnterBackgroundScript"
10:01:25.916010 Current file: "PlaceHolder". User "iPhone 14 Pro" on host "MyMacM1.local"
10:01:25.916166 Result: 0 (No error)
10:01:27.207005 ScriptTrigger called with inside DidEnterBackgroundScript

As you see the script and evaluate both run for WillResignActive and a bit later with DidEnterBackground. And we activate the app later again:

10:01:52.380015 Evaluate "MBS("Log"; "inside WillEnterForegroundEvaluate")"
10:01:52.380122 Current file: "PlaceHolder". User "iPhone 14 Pro" on host "MyMacM1.local"
10:01:52.380304 inside WillEnterForegroundEvaluate
10:01:52.380460 Result: 0 (No error)
10:01:52.380604 Start Script "ScriptTrigger" in file "PlaceHolder" with control Pause
10:01:52.380709 Parameter: "inside WillEnterForegroundScript"
10:01:52.380793 Current file: "PlaceHolder". User "iPhone 14 Pro" on host "MyMacM1.local"
10:01:52.380937 Result: 0 (No error)
10:01:52.677940 Evaluate "MBS("Log"; "inside DidBecomeActiveEvaluate")"
10:01:52.678073 While running script "ScriptTrigger" in file "PlaceHolder". User "iPhone 14 Pro" on host "MyMacM1.local"
10:01:52.678247 inside DidBecomeActiveEvaluate
10:01:52.678427 Result: 0 (No error)
10:01:52.678719 Start Script "ScriptTrigger" in file "PlaceHolder" with control Pause
10:01:52.678825 Parameter: "inside DidBecomeActiveScript"
10:01:52.678930 While running script "ScriptTrigger" in file "PlaceHolder". User "iPhone 14 Pro" on host "MyMacM1.local"
10:01:52.680781 Result: 0 (No error)
10:01:52.851729 ScriptTrigger called with inside WillEnterForegroundScript
10:01:52.852626 ScriptTrigger called with inside DidBecomeActiveScript

As you see we first get the evaluate and the script for WillEnterForeground. After that DidBecomeActive is run. Due to evaluate being quicker in execution, that happens first, before later the scripts kick in.

Now it can happen, that some time passes and you get the significant time change trigger:

00:00:05.011715 Evaluate "MBS("Log"; "inside SignificantTimeChangeEvaluate")"
00:00:05.013731 Current file: "PlaceHolder". User "iPhone 14" on host "MyMacM1.local"
00:00:05.014559 inside SignificantTimeChangeEvaluate
00:00:05.015134 Result: 0 (No error)
00:00:05.015356 Start Script "ScriptTrigger" in file "PlaceHolder" with control Pause
00:00:05.015403 Parameter: "inside SignificantTimeChangeScript"
00:00:05.015486 Current file: "PlaceHolder". User "iPhone 14" on host "MyMacM1.local"
00:00:05.020317 Result: 0 (No error)
00:00:05.020773 ScriptTrigger called with inside SignificantTimeChangeScript

As you see, we just waited for midnight to get this logged. But if your app does something time sensitive or likes to run a script when time zone or day changes, you may want to use this trigger.

Let us know if you have questions about this.