Obj-C version is available here.
Author: Corinne Krych, Daniel Passos
Level: Intermediate
Technologies: Swift 4, iOS, RHMAP, CocoaPods.
Summary: A demonstration of how to get started with remote cloud call in RHMAP.
Community Project: Feed Henry
Target Product: RHMAP
Product Versions: RHMAP 3.7.0+
Source: https://github.com/feedhenry-templates/helloworld-ios-swift
Prerequisites: fh-ios-swift-sdk: 6+, Xcode: 9+, iOS SDK: iOS 9+, CocoaPods 1.3.0+
Simple native iOS app to test your remote cloud connection in RHMAP. Its server side companion app: HelloWorld Cloud App. This template app demos how to intialize a cloud call and make calls to cloud endpoints. The app uses fh-ios-swift-sdk.
If you do not have access to a RHMAP instance, you can sign up for a free instance at https://openshift.feedhenry.com/.
This application and its cloud services are available as a project template in RHMAP as part of the "Native iOS Hello World Project" template.
If you wish to contribute to this template, the following information may be helpful; otherwise, RHMAP and its build facilities are the preferred solution.
- Clone this project
- Populate
iOS-Template-App/fhconfig.plist
with your values as explained here. - Run
pod install
- Open Helloworld-app-iOS.xcworkspace
- Run the project
In helloworld-ios-app/HomeViewController.swift
the FH.init call is done:
override func viewDidLoad() {
result.contentInset = UIEdgeInsetsMake(20.0, 20.0, 10.0, 10.0);
super.viewDidLoad()
// Initialized cloud connection
FH.init {(resp: Response, error: NSError?) -> Void in
if let error = error {
print("FH init failed. Error = \(error)")
self.result.text = "Please fill in fhconfig.plist file."
}
print("initialized OK")
self.button.hidden = false
}
}
In helloworld-ios-app/HomeViewController.swift
the FH.init call is done:
@IBAction func cloudCall(_ sender: AnyObject) {
name.endEditing(true)
let args = ["hello": name.text ?? "world"]
FH.cloud("hello", method: HTTPMethod.POST,
args: args as [String : AnyObject]?, headers: nil,
completionHandler: {(resp: Response, error: NSError?) -> Void in
if let _ = error {
print("initialize fail, \(resp.rawResponseAsString)")
self.button.hidden = true
}
if let parsedRes = resp.parsedResponse as? [String:String] {
self.result.text = parsedRes["msg"]
}
})
}
If your RHMAP is depoyed without TLS1.2 support, open as source blank-ios-app/blank-ios-app-Info.plist.plist
uncomment the exception lines:
<!--
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
-->