iOS App : Porting Code to App

0 votes

So, I'm attempting to port the post action(not the format) of this code to an iOS app. 

center><br>
<br>
<br>
<form action="https://api.particle.io/v1/devices/your-device-ID-goes-here/led?access_token=your-access-token-goes-here" method="POST">
Tell your device what to do!<br>
<br>
<input type="radio" name="args" value="on">Turn the LED on.
<br>
<input type="radio" name="args" value="off">Turn the LED off.
<br>
<br>
<input type="submit" value="Do it!">
</form>
</center>
and now I'm stuck with this.
import UIKit

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.


        let myUrl = NSURL(string: "https://api.particle.io/v1/devices/your-device-ID-goes-here/led?access_token=your-access-token-goes-here")
        let request = NSMutableURLRequest (URL:myUrl!)
        request.HTTPMethod = "POST"
}


Kindly help me out with how to proceed.

Thanks.

Jan 18 in IoT (Internet of Things) by Upasana
• 8,410 points
15 views

1 answer to this question.

0 votes

If you make a post, missing parameters ... it would have to see this.

let request = NSMutableURLRequest(URL: NSURL(string: "http://www.thisismylink.com/postName.php"))
request.HTTPMethod = "POST"
let postString = "id=13&name=Jack"
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
data, response, error in

if error != nil {
    println("error=\(error)")
    return
}

println("response = \(response)")

let responseString = NSString(data: data, encoding: NSUTF8StringEncoding)
println("responseString = \(responseString)")
}
task.resume()

Kindly see this framework on git for more detail

https://github.com/daltoniam/SwiftHTTP

answered Jan 18 by Shubham
• 13,110 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer

Unable to start Bluemix MobileFirst services starter app

 Having used both the Classic UI and the "New Experience" ...READ MORE

answered Sep 11, 2018 in IoT (Internet of Things) by Annie97
• 2,190 points
17 views
0 votes
1 answer

Python Code to retrieve data from Device to IBM Bluemix

You connect as a device -> import ibmiotf.device. ...READ MORE

answered Sep 18, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
58 views
0 votes
1 answer

Downloading source code of Android Things

No because AndroidThings is still in preview ...READ MORE

answered Jul 5, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
399 views
0 votes
1 answer

URL Scheme for iOS Home App

I think you could try doing it ...READ MORE

answered Nov 16, 2018 in IoT (Internet of Things) by nirvana
• 3,060 points
55 views
0 votes
1 answer

Detecting BLE beacons that are not ibeacons on IOS

You'll have to understand that CoreLocation is ...READ MORE

answered Aug 1, 2018 in IoT (Internet of Things) by nirvana
• 3,060 points
34 views
0 votes
1 answer

Using Post and Get for Embedded System Communication

Twitter would be a great place to ...READ MORE

answered Sep 4, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
30 views
0 votes
1 answer

Get User Group in Swift using AWS Cognito

The groups are exposed in the ID ...READ MORE

answered Nov 12, 2018 in AWS by Priyaj
• 56,160 points
177 views
0 votes
1 answer

How to detect presence of a device in a WiFi network?

Finding the mac-address would probably work. Basically, ...READ MORE

answered Nov 16, 2018 in IoT (Internet of Things) by Shubham
• 13,110 points
54 views
0 votes
1 answer

Detecting when a sensor is not sending data to Orion CB in FiWARE

Orion in itself has no such mechanism ...READ MORE

answered Nov 21, 2018 in IoT (Internet of Things) by Shubham
• 13,110 points
25 views