Using mergNotify

mergNotify is an iOS and OS X external that adds a command to request a notification callback whenever the Notification Center receives the event notification.

Many classes in the iOS SDK have notifications that the external enables your stack to receive. For example, two notifications from the UIApplication class are UIApplicationWillResignActiveNotification and UIApplicationDidBecomeActiveNotification.

These notifications are sent when the app is being opened and closed, the device is switched on or off with the app running or when some other system notification is presented over the app.

There are many other examples of useful notifications in the iOS sdk documentation.

Additionally you can use the external to allow multiple LiveCode controls to receive the same notification which may aid in code modularity.

Registering for notifications

To register for notifications use the mergNotify command with the name of the notification your control should receive.

on openStack
  mergNotify "UIApplicationWillResignActiveNotification"
  mergNotify "UIApplicationDidBecomeActiveNotification"
end openStack
Click to copy

The notification is sent to the calling control whenever it occurs.

Responding to notifications

To respond to a notification add a handler for the notification.

The notification will be sent with a single pUserInfo parameter. This parameter is the result of using the description method of the NSNotification userInfo dictionary. Some notifications do not have any userInfo so this parameter may be empty.

local sTimeResignedActive
constant kMaxTimeResignedBeforeSessionExpires = 300

on UIApplicationWillResignActiveNotification pUserInfo
  put the seconds into sTimeResignedActive
end UIApplicationWillResignActiveNotification

on UIApplicationDidBecomeActiveNotification pUserInfo
  if sTimeResignedActive <> "" then
    if the seconds - sTimeResignedActive > kMaxTimeResignedBeforeSessionExpires then
       -- show session expired so login again UI
    end if
  end if
end UIApplicationDidBecomeActiveNotification
Click to copy

Testing and building standalones

When using mergNotify it is best to choose "Select inclusions for the standalone application" in the General pane of the Standalone Application Settings and ensure mergNotify is selected on the Inclusions pane.

The mergNotify extension is not always picked up when searching for inclusions.

2 Comments

Mark

Was this implemented differently in a recent version of LC? I seem to recall reading something about that in some release note but cannot find it anymore. Thanks

Panos Merakos

Hello Mark,

The functionality of mergNotify remains the same. However, since LC 10 DP-x (I do not remember the exact version) - we have added the suspend and resume messages to mobile, so you can just use these directly, instead of using mergNotify to subscribe to specific notifications when the app goes into background/foreground

Kind regards,
Panos
--

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.