Components and services

The following section compares commonly used components and services on both platforms.

WebView

Both iOS and BlackBerry 10 let you display web content in your app.

UIWebView in iOS

WebView in BlackBerry 10

Screen showing a UIWebView.
Screen showing a WebView.

Characteristics of UIWebView

UIWebView contains core classes that display web content.

UIWebView simplifies the process of displaying content that contains MIME types by automatically creating the views needed to display a page when a user clicks a link.

You can enable editing in a UIWebView, and control the editing behavior of the current selection programmatically.

UIWebView allows access to JavaScript from Objective C, and vice versa.

Characteristics of WebView

The WebView control displays web content that is defined in QML and bundled with your application.

Content is always loaded asynchronously and can be reported using the loadingChanged(), loadProgressChanged(), and urlChanged() signals.

The user can interact with the WebView content, and JavaScript code can be executed on the page.

Implementing a WebView in your app

The following sample demonstrates placing a WebView in a ScrollView and enabling scroll and zoom functionality.

ScrollView {
id: scrollView
scrollViewProperties {
    scrollMode: ScrollMode.Both
    pinchToZoomEnabled: true
}
layoutProperties: StackLayoutProperties { spaceQuota: 1.0 }
 
Container {
    background: Color.LightGray
 
    WebView {
        id: webView
        url: "http://example.com"
 
        onMinContentScaleChanged: {
            scrollView.scrollViewProperties.minContentScale = minContentScale;
        }
 
        onMaxContentScaleChanged: {
            scrollView.scrollViewProperties.maxContentScale = maxContentScale;
        }
    }
}

For more information on the WebView control, see the WebView reference.

Networking REST calls

Representational State Transfer (REST) is an architecture style that allows networked applications to use HTTP to make calls between computers. Both iOS and BlackBerry 10 support the use of REST calls in your app, which helps to simplify the process of posting, reading, and deleting data.

Making a simple REST call

The following sample demonstrates how to make a simple REST call in an iOS app:

NSURL *url = [NSURL URLWithString:
@"http://search.twitter.com/search.json?q=@testn"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];

On BlackBerry 10, the same REST call is made using a QNetworkRequest:

QNetworkRequest request=QNetworkRequest();
request.setUrl(QUrl("http://search.twitter.com/search.json?q=@testn"));
QNetworkAccessManager *m = new QNetworkAccessManager(this);

For more information about networking, see Networking.

Notifications

Notifications let users know that an application has information for them. The information can be a message, an update, or a scheduled event. The following is a comparison of how notifications are handled on iOS and BlackBerry 10.

Notifications in iOS

Notifications in BlackBerry 10

A notification in iOS.
A notification in BlackBerry 10.

Characteristics of notifications in iOS

Notifications alert users to information available to them in an app.

Both local notifications and push notifications are available.

Both local and push notifications have the same appearance to the user.

Push notifications allow for transmission of 256 bytes of data.

Characteristics of notifications in BlackBerry 10

Notifications alert users that an event has occured.

Both local notifications and the Push Service are available.

Both local notifications and push messages have the same appearance to the user.

The Push Service allows for up to 8KB of information to be sent.

Notifications that include a title appear in the BlackBerry Hub. If a notification doesn't include a title, a new item indicator appears on your app icon.

You can specify a sound for your app's notification.

Implementing local notifications in your app

The following code sample creates a UI with two Button objects for creating and clearing a notification. You set the title and body of the notification using text input from the UI.

import bb.cascades 1.0
import bb.platform 1.0
 
Page {
    Container {
        attachedObjects: [
            Notification {
                id: alert
                onTitleChanged: {
                    console.log(value);
                }
            }
        ]
        layout: DockLayout {
        }
        Container {
            verticalAlignment: VerticalAlignment.Center
            horizontalAlignment: HorizontalAlignment.Center
            TextField {
                id: title
                hintText: "Title"
                text: "title"
            }
            TextField {
                id: body
                hintText: "Body"
                text: "body"
            }
            Button {
                text: "Fire the Notification!"
                onClicked: {
                    alert.title = title.text;
                    alert.body = body.text;
                    alert.category = "vibrate";
                    alert.soundUrl = "asset:///sounds/mysound.wav"
                    alert.notify();
                }
                horizontalAlignment: HorizontalAlignment.Center
            }
            Button {
                text: "Kill the Notification!"
                onClicked: {
                    alert.clearEffectsForAll();
                }
                horizontalAlignment: HorizontalAlignment.Center
            } // end Button
        } // Container
    } // Container with attachedObjects
} // Page

Displaying a notification

You can use a  NotificationDialog to display a dialog when your notification event occurs. A NotificationDialog contains the same content as a Notification with more properties for displaying the dialog. You can use the repeat property to repeat the notification. You can specify the button the user must tap to dismiss the NotificationDialog by using the buttons property. You must add at least one button to a NotificationDialog.

NotificationDialog {
    id: alertdialog
    title: "A notification dialog"
    body: "This text is displayed in the dialog body."
    category: "vibrate"
    repeat: true
    soundUrl: "asset:///sounds/thunder.wav"
}   
 
...
 
Button {
    text: "Fire the Notification Dialog!"
    horizontalAlignment: HorizontalAlignment.Center
 
    onClicked: {
        alertdialog.title = title.text;
        alertdialog.body = body.text;
        alertdialog.category = "vibrate";
        alertdialog.soundUrl = "app/native/assets/sounds/test.wav"
        alertdialog.show();
    }
}

For more information on notifications, see Notifications.

Invocation handlers

Invocation allows an application to launch another application from within its own UI. Invocation allows an app to offer additional features and functionality without losing focus. The following is a comparison of how apps are invoked on iOS and BlackBerry 10.

Invocation handlers in iOS

Invocation framework in BlackBerry 10

Screen showing invocation on iOS.
Using invocation in the Pictures app.

Characteristics of invocation handlers

Invocation handlers facilitate inter-app communication.

Invocation handlers manage all interactions that support file preview and menu display.

Invocation handlers support a modal view used to select specific applications to interact with a file.

Characteristics of the invocation framework

The Invocation framework facilitates inter-app communication.

The invocation framework allows the user to perform an action such as share, open, or send a .doc file by email using another application.

When an application calls for an invocation of content, the invocation framework provides services or applications that can carry out an action on that particular content.

The invocation framework allows an application to become discoverable by allowing itself to register as a target.

There are two types of invocation: bound and unbound. With bound invocation, the client application identifies itself as a target. In unbound invocation, the invocation framework determines the target.

Implementing invocation in your app

To send an invocation request, you must use the InvokeManager class. Bound invocation explicitly identifies the target application that handles the invocation by specifying the target parameter of the InvokeRequest class.

InvokeManager *iManager = new InvokeManager(this);
InvokeRequest iRequest;
iRequest.setTarget("com.example.MyTarget");
InvokeReply *iReply = iManager->invoke(iRequest);

// If any Q_ASSERT statement(s) indicate that the slot 
// failed to connect to the signal, make sure you know exactly
// why this has happened. This is not normal, and will cause your 
// app to stop working
bool connectResult;

// Since the variable is not used in the app, this is added 
// to avoid a compiler warning
Q_UNUSED(connectResult);

connectResult = QObject::connect(iReply, SIGNAL(finished()), this,
                                 SLOT(myInvokeReplySlot()));

// This is only available in Debug builds
Q_ASSERT(connectResult);

In unbound invocation, the client application allows the invocation framework to determine the best fit target using parameters defined in an app's bar-descriptor.xml.

InvokeManager *iManager = new InvokeManager(this);
InvokeRequest iRequest;
iRequest.setMimeType("image/png");
InvokeReply *iReply = iManager->invoke(iRequest);

// If any Q_ASSERT statement(s) indicate that the slot 
// failed to connect to the signal, make sure you know exactly
// why this has happened. This is not normal, and will cause your 
// app to stop working
bool connectResult;

// Since the variable is not used in the app, this is added 
// to avoid a compiler warning
Q_UNUSED(connectResult);

connectResult = QObject::connect(iReply, SIGNAL(finished()), this,
                                 SLOT(myInvokeReplySlot()));

// This is only available in Debug builds
Q_ASSERT(connectResult);

For more information on the invocation framework, see App integration.

Gesture mapping

On touch screen devices, gestures are required for a user to interact with an application.

Cascades supports most gestures, but you might need to use some underlying C APIs to handle gestures which are not directly supported by Cascades.

The following table outlines the equivalent gestures between iOS and BlackBerry 10.

Gesture

UIKit class on iOS

Gesture classes and handlers on BlackBerry 10

Long press

UILongPressGestureRecognizer

LongPressHandler

Zooming in and out

UIPinchGestureRecognizer

PinchHandler

Press and tap

Not applicable

Customized gesture handler

Swiping

UISwipeGestureRecognizer

Customized gesture handler

Tapping

UITapGestureRecognizer

TapHandler

DoubleTapHandler

Panning or dragging

UIPanGestureRecognizer

PinchHandler

Tapping with two fingers

Not applicable

Customized PinchHandler

Rotating

UIRotationGestureRecognizer

PinchHandler

For more information on gestures, see Touch screen input.

File system

A file system handles the persistent storage of files and apps on a device. Files are stored in a hierarchical system, which allows for improved efficiency in how files are organized and retrieved. The following is a comparison of iOS and BlackBerry 10 file systems.

File system in iOS

File system in BlackBerry 10

Diagram showing the iOS file system.
Diagram showing the file system in BlackBerry 10.

Characteristics of the file system in iOS

During app installation, the setup application creates a home directory for the app, places the app in that directory, and creates any necessary key directories.

Users do not have direct access to the file system.

An app's interactions with the file system are limited to directories in the app's home directory.

You cannot write files to directories without the appropriate security privileges.

Apps are expected to store files in easily discoverable places and restrict users from accessing them.

Characteristics of the file system in BlackBerry 10

The file system contains three directories:
  • The working directory
  • The assets directory
  • The shared directory

Applications cannot create new directories in the working directory.

To access shared folders, the appropriate permission must be specified in the bar-descriptor.xml file (when viewing the descriptor file in the Source view, the files permission is known as the access_shared permission).

For more information on the file system in BlackBerry 10, see File system access for apps.

Last modified: 2014-09-30



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus