Introduction to Beta features in AppStudio 2.0

2567
12
06-29-2017 04:56 PM
nakulmanocha
Esri Regular Contributor
2 12 2,567

New Capabilities are introduced in the AppFramework as a part of AppStudio 2.0. These capabilities are not provided natively by Qt. Following capabilities are currently in beta

  •     Local Notification

  •     Vibration

  •     Background Location

  •     Promises

 

These capabilities are currently in Beta. What does that mean?

 What it means is that we are looking forward to your feedback, the use cases, what you like and what you want us to  improve upon. It also means that if you choose to implement these plugins in Production App. Future changes may affect  your app may require additional changes to support these functionalities in your app.

1. Local Notification - This is a new plugin added to the AppFramework. It provides developers the ability to implement in-app notification to end users such as an alert, message or geotification. When the Local Notification gets triggered on the client device the Notification icon appears in the Notification bar which is same as the application icon. The Notification icon cannot be customized or modified. Users may choose to have one or multiple notifications within the app. Every notification scheduled has a corresponding id available to distinguish between multiple Local Notifications.

 Note:- An app running within Player or AppStudio Desktop (AppRun) will show the notification icon of Player or                      AppRun respectively when triggered.

 Platform Support

  •     iOS
  •     Android
  •     Windows
  •     Mac
  •     Linux

 How to implement Local Notification in an AppStudio App?

  • Use the following import statement

        import ArcGIS.AppFramework.Notifications.Local 1.0

  • Enable the “Local Notification” capability within the AppSettings of the App
  •      Use the component "LocalNotification" which takes three input parameters to schedule a notification
    •      Title – The title of the message
    •       Message – The description of the message
    •       Time (in seconds)- Time after which the notification will be triggered on the end user device. 

 Sample Code   

 API Reference

   Properties

  • bool supported (read only)- Returns a boolean if the device supports local notification.

       Note: This property is supported on Android API 19+ versions.

   Methods                            

  • object schedule(string title, string message, int timeInSeconds) -  returns a Variant object which is id of the scheduled notification    
  • Title - The title of the message as string value
  • Message -The description of the message as string value
  • Time (in seconds) -Time after which the notification will appear on the end user device as int

               For e.g. 5 seconds means the notification will be triggered in 5 second                 

               var id = notification.schedule(title, message, duration)

  • bool clear(object id) -This method will clear the pending notification from the list of scheduled notifications
    • object id - The id of the notification to be clear.
    • Returns bool - Indicates whether the notification is cleared from the list of scheduled notifications. 

             For e.g. 

             bool success = notification.clear(id) 

             Note: It will return false for invalid inputs and for notifications which have already triggered.

  • void clearAll() - This method clears all the pending (yet to be triggered) and active (already triggered) notifications along with badge numbers for iOS apps.

             For e.g. 

             notification.clearAll()

  Signals

  • triggered(object id) - This signal is emitted when the  local notification is triggered.
    • object id-It takes an id of the scheduled notification.

2. Vibration (Singleton) - New plugin added in AppFramework with AppStudio 2.0 version. This allows developers to enable vibration within an app. It is a non visual feedback or alert. Common use cases to provide vibration are to indicate an event such a message received or finished creating a model making a network request or just an alert etc.

Note: Currently, there is no way to provide number of seconds as an input for it to vibrate. On android device, it will vibrate for 1 second and on iOS it will use the system default.

          

Platform Support

  •      iOS
  •     Android
  •     Windows
  •     Mac
  •     Linux

How to implement Vibration in the AppStudio App?

  •     Use the following import statement

      import ArcGIS.AppFramework.Notifications 1.0

  •     Enable the Vibration capability within the AppSettings of the App
  •     Call the Vibration.vibrate()

 

API Reference

   Properties

  • bool supported - Returns a boolean value indicating whether your device supports vibration or not.

 

   Methods

  • void vibrate() - Method call to initiate a vibration on the client device from the app. The device will continue to vibrate for system default vibration settings (in seconds) or until the app is closed.

        For e.g.

          if(Vibration.supported) {

                 Vibration.vibrate()

           }

 

3. Background Location - New capability has been introduced to AppStudio 2.0 which allows the apps to use location data in background mode. Some of the common use cases using this capability are logging location data using position source, or trigger a notification, geo-fencing etc. This capability is currently available for mobile platforms only as this is already supported on desktop.

Platform Support

  •     iOS
  •     Android
  •     OSX
  •     Windows
  •     Linux

 

How to implement Background Location in the AppStudio App?

  •      Enable the Background Location capability in AppSettings of the App

Best Practices

You can monitor the state of the application using the following property 

 Qt.application.active

4. Promises - Often while creating your apps, you may want to make something happen after something else is done. You may want to want to make an asynchronous request and perform something on completion of the request. Or you may simply want to execute set of operations in a particular sequence. Promises can be used to manage such asynchronous computation, allowing for separate processes to continue in parallel.

 

Promises are a pattern that helps with one particular kind of asynchronous programming: a function (or method) that returns a single result asynchronously. One popular way of receiving such a result is via a callback. Promises provide a simpler alternative for executing, composing, and managing asynchronous operations when compared to traditional callback-based approaches. The Promise object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value.

 

A promise can be in one of 3 states:

  • Pending - the promise’s outcome hasn’t yet been determined, because the asynchronous operation that will produce its result hasn’t completed yet.
  • Fulfilled - the asynchronous operation has completed, and the promise has a value.
  • Rejected - the asynchronous operation failed, and the promise will never be fulfilled. In the rejected state, a promise has a reason that indicates why the operation failed.

When a promise is pending, it can transition to the fulfilled or rejected state. Once a promise is fulfilled or rejected, however, it will never transition to any other state, and its value or failure reason will not change.

12 Comments
by Anonymous User
Not applicable

Awesome, great work from the AppStudio team - looking forward to checking out these new features!

Can you clarify please, will these features be able to be implemented in existing apps using the old runtime, or only if using the new Quartz runtime v100?

Thanks

-Paul

nakulmanocha
Esri Regular Contributor

These features are independent of the Runtime version. These are features added to the AppFramework.

-Nakul

DustinBaumbach1
Occasional Contributor

Great job guys! These features look really interesting. Just curious if the promises can be used in the AddDetails page of the quick report app so that if you choose a certain field, the rest of the fields will populate accordingly?

-Dustin

MassimilianoSantini
New Contributor

Hi, what about insert an hiperlink in local notification messages, is it possible or the only available option is plain text?

Thank you!

Massimiliano

SiddeshPillai1
Esri Contributor

Hi Massimiliano,

No. It is not possible to insert hyperlinks as notification messages are only displayed as plain text. 

Best,

Siddesh

MassimilianoSantini
New Contributor

Hi Siddesh,

thank you. Mmm perhaps I could use the app as a bridge...what type of event or parameters are launched or passed to the app when I click on the local notification?

I mean something like Bundle object in Android Intent object. I was wondering if there's the way to catch inside the app if
it's launched from the launch icon or from the local notification widget.

Thank you

Massimiliano

SiddeshPillai1
Esri Contributor

Hi Massimiliano,

what type of event or parameters are launched or passed to the app when I click on the local notification?

Android directs notification messages to the system tray. When you click on the notification, opens the app launcher by default.

Based on this "I mean something like Bundle object in Android Intent object. I was wondering if there's the way to catch inside the app if it's launched from the launch icon or from the local notification widget".

I understand that you looking to open a specific page when you click on the notification by providing a payload.  

No, it is not possible with local notification as QML based UI run on a different thread than the Application activity. 

Best,

Siddesh

MassimilianoSantini
New Contributor

Hi Siddesh,

thank you very much!

I have something else to ask you about Background Location.

Esri writes "New capability has been introduced to AppStudio 2.0 which allows the apps to use location data in background mode. "

What does exactly mean background mode? When my app runs in background, or, like Android services, when the mobile s.o. startup?

As you have already understood, I need a background services who does the geolocation and notification even if the app is not running at all.

Can I do it? Is there any examples?

Thank you.

Massimiliano

SiddeshPillai1
Esri Contributor

Hi Massimiliano,

What does exactly mean background mode? When my app runs in background, or, like Android services, when the mobile s.o. startup?

Background Location is a device mode and it doesn’t have an API. You just need to go your app settings and enable Background Location capability. If enabled, you can use PositionSource even when your app is in suspended state.

Currently, it doesn't involve any registration of Android services and the same goes for iOS. 

As you have already understood, I need a background services who does the geolocation and notification even if the app is not running at all.

Can I do it? Is there any examples?

For e.g.

PositionSource {

    id: src

    updateInterval: 1000

    active: true

 

    onPositionChanged: {

        var coord = src.position.coordinate;

 

// you should view the console logs when app is in background when the capability is turned on

        console.log("Coordinate:", coord.longitude, coord.latitude);

    }

}

If you run the above snippet with Background Location enabled, you will notice the console logs when your app is in suspended state. However, if you kill the app it won't work. You can include LocalNotification 'schedule' method in onPositionChanged to better suit your app alerts.

For better app practice when using this capability, It will be handy to use Qt application state. Refer the belowlink 

Qt Namespace | Qt Core 5.9 

Try it out. Let me know if you have any questions. 

Best,

Siddesh 

MassimilianoSantini
New Contributor

Hi,

in iOS environment

var lnID = notification.schedule(...)

return an ID that it is not the same id triggered in

LocalNotification  {
        id: notification
        onTriggered: {
           notification id not equal lnID
        }
}

In Android it works fine.

Am I doing something wrong?

Thank you

Massimiliano

FarWestGEOConsultants
New Contributor II

Are there any licensing implications ?
Not sure if this notification feature is available with Basic or if Standard would be required.

by Anonymous User
Not applicable

Hi,

AppStudio Standard license is required for Local notification.

Thanks,

Tina