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

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

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.

0 Comments

Add your comment

E-Mail me when someone replies to this comment