Before You Begin
This 15-minute tutorial shows you how to build an Apple iOS application that simulates a virtual device and sends a message to Oracle Internet of Things (IoT) Cloud Service.
Background
Oracle IoT Cloud Service provides communication services between devices and enterprise applications. In this tutorial, you build a simulated device in an Apple iOS application, and then transmit a Hello World message to Oracle IoT Cloud Service.
What Do You Need?
- Access to an instance of Oracle IoT Cloud Service
- A computer running Apple macOS 10.12.6 or later
- Xcode Integrated Development Environment (IDE) version 9.2 or later
- The latest version of the iOS Client Software Library from Oracle Technologies Network
- The
info.plist.part
file - The
ViewController.swift
file - Completion of Configuring an Application in Oracle Internet of Things Cloud Service and the values of the configuration data
- Experience with Swift programming in Xcode environment
Install and Configure the Required Software
- Download the latest version of the iOS Client Software Library binaries file from the Oracle Technologies Network downloads page.
- Open a command-line interface and go to the directory where you downloaded your library.
- Extract the
iotcs-csl-ios-bin-release.zip
file, whererelease
is the release and version number.unzip iotcs-csl-ios-bin-release.zip
- Verify that your library is extracted under the
iotcs/csl/ios/lib
directory.
Create Your Virtual Device Project
- Open Xcode IDE.
- To create a new project, click File, then New, and then Project.
- In New Project wizard, select iOS, then Single View Application, and then click Next.
- Enter the following values, leave the rest of the fields with the default values, and then click Next:
- Product Name:
IOSHelloWorld
- Organization Identifier:
com.oracle.iot
Description of the illustration project_details.png - Product Name:
- Select the following values and click Create:
- Source Control: Selected
- Git Repository: My Mac
- In the Embedded Binaries section, click Add, then in the Choose items to add dialog box, click Add Other.
- Browse to your iotcs/csl/ios/lib directory, select the following frameworks, and click Open.
DeviceLib.framework Alamofire.framework CommonCrypto.framework SwiftyJson.framework SQLite3Swift.framework
- Select the following options and click Finish:
- Destination: Selected
- Added folders: Create folder references
Description of the illustration file_options.png
Configure Your Virtual Device Project
- Go to Project Navigator, select iOSHelloWorld, and then General. Verify the list of the following frameworks are listed:
Embedded Binaries- DeviceLib.framework
- CommonCrypto.framework
- Alamofire.framework
- SwiftyJson.framework
- SQLite3Swift.framework
Linked Frameworks and Libraries- DeviceLib.framework
- CommonCrypto.framework
- Alamofire.framework
- SwiftyJson.framework
- SQLite3Swift.framework
- libsqlite3.tbd
- To apply a workaround for a known bug, go to the Capabilities tab and set Keychain Sharing to ON.
Description of the illustration capabilities.png - To set build settings, click Build Settings and then enter
FRAMEWORK_SEARCH_PATHS
in the Search field. - Double-click in the
FRAMEWORK_SEARCH_PATHS
field. To add a new value, click +, enter~/iotcs/csl/ios/lib
, and press Enter. - Replace
FRAMEWORK_SEARCH_PATHS
withSWIFT_INCLUDE
in the Search field and press Enter. - Double-click in the
SWIFT_INCLUDE
field. To add a new value, click +, enter~/iotcs/csl/ios/lib/IPTools
, and press Enter. - Replace
SWIFT_INCLUDE
withSWIFT_VERSION
in the Search field and press Enter. - To set the value to YES, click the No value.
- Go to Project Navigator and expand the iOSHelloWorld project. Right-click info.plist, select Open As, then Source Code, and add the content of the
info.plist.part
file.
Note: Replacemyinstance-myidentitydomain.iot.us.oraclecloud.com
with the URL of your Oracle IoT Cloud Service instance. - Go to Project Navigator and click the iOSHelloWorld project. Then from the menu items, select Add Files to "iOSHelloWorld" option, browse to your provisioning file, and click Add.
- Verify that your provisioning file is added to your project.
Description of the illustration ios_project.png
Send your First Message
- Go to Project Navigator and expand the iOSHelloWorld project, double-click the
ViewController.swift
file, and add the content of theViewController.swift
file that you downloaded in the What do you need? section.
Note: ReplacePROVFILE5
andPASSPHRASE6
with the configuration data values you obtained when you completed the Configuring an Application in Oracle Internet of Things Cloud Service tutorial. - To execute your project, click Run, then in the Debugger Output window you see the
"Virtual device created"
message. - To stop the display of verbose OS debug messages, on the debugger window of Xcode 8.1, go to the Environment Variables section of the scheme and set the OS_ACTIVITY_MODE as disable.
Verify Your Message
- Sign in to your Oracle IoT Cloud Service instance.
- On the Oracle IoT Cloud Service home page, under Applications, click Oracle IoT Asset Monitoring.
- Select Data, and then in Filter By, select Device.
- Verify that the Messages table contains your message and review the value of Message Content.
Description of the illustration messages_table.png