I have an iOS app written in Objective-c and a Wordpress Website with WooCommerce. How can I connect them?

坚强是说给别人听的谎言 提交于 2019-12-21 20:37:34

问题


I built a website and set it up with the WooCommerce plugin to handle my eCommerce. That system works great.

I built an iOS app that is not connected to my Wordpress site at all. I am clearly a novice, but I am trying to understand how to connect these two systems.

Usernames/Passwords, Purchases, Shipping, etc....

Can anyone point me in the right direction of a solution, because I am coming up blank on my search. Thanks!


回答1:


Step 1) Install one of the plugins for Wordpress authentication. (P.S. I used basic authentication in the example below.)

Step 2) Go to WooCommerce > Settings > API > Keys/Apps, and add a new key and then generate API Key. It will create consumer_key and consumer_secret for you.

Step 3) Enable REST API in the WooCommerce settings. (To enable the REST API within WooCommerce, visit the WooCommerce > Settings > API tab and tick the Enable REST API checkbox.) source

Step 4) I assume that you are developing an app with Swift. If so see the code below for getting user details and orders for example. Don't forget to include Alamofire framework in your project.

// to get user info
let plainString = "WP_username:WP_password" as NSString
let plainData = plainString.dataUsingEncoding(NSUTF8StringEncoding)
let base64String = plainData!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))


let headers = [
    "Authorization": "Basic " + base64String
]

Alamofire.request(.GET, "http://yourwebsite.com/wp-json/wp/v2/users/me?_envelope=1&context=embed", headers: headers)
    .responseJSON{ response in switch response.result {
    case .Success(let JSON):
        print("Success with JSON: \(JSON)")

    case .Failure(let error):
        print("Request failed with error: \(error)")
        }
}


// to get a customer's orders
Alamofire.request(.GET, "https://yourwebsite.com/wc-api/v3/customers/USER_ID/orders", parameters:    
["consumer_key":"ck_XXX", "consumer_secret":"cs_XXX"])
         .responseJSON{ response in switch response.result {
            case .Success(let JSON):
                let response = JSON as! NSDictionary
                print(response)

            case .Failure(let error):
                print("Request failed with error: \(error)")
          }
}    



回答2:


Well I don't if this is what you want but you could just put the website in a web view




回答3:


You may want to look into the WooCommerce REST API. Sorry that I don't know if it offers everything you're looking for, but researching that might be a good starting point.



来源:https://stackoverflow.com/questions/35095433/i-have-an-ios-app-written-in-objective-c-and-a-wordpress-website-with-woocommerc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!