Many people have been tearing their hair out looking for a solution to the invalid signature issue when sending requests to the WooCommerce api from an iOS app.
I have put together the solution here.
Many people have been tearing their hair out looking for a solution to the invalid signature issue when sending requests to the WooCommerce api from an iOS app.
I have put together the solution here.
You must be logged in to post a comment.
I am providing the solution for the invalid signature issue when sending requests to the WooCommerce API from an iOS app.
To use WooCommerce in the iOS app, the requests must authenticate using OAuth 1.0. In iOS, regardless of whether the app is being written in Objective-C or Swift, AFNetworking makes life easier when writing requests.
Follow this procedure to setup your requests:
Add AFNetworking to your project using Cocoapods. Your podfile will look like this:
Save this in your project directory and run
pod install
in terminal.For the next step, we must install AFNetworking 1.3.4. That’s why it says 1.3.4 in the podfile.
Next, download this project from github: https://github.com/khanghoang/-WooClient
Unzip it and copy
AFOAuth1Client.h
,AFOAuth1Client.m
,AFOAuth1OneLeggedClient.h
,AFOAuth1OneLeggedClient.m
,AFOAuth1OneLeggedClientWooParser.h
,AFOAuth1OneLeggedClientWooParser.m
to your project.Now we need to modify these files a bit. Open
AFOAuth1Client.h
and find theAFHMACSHA1Signature()
method.Look for these lines:
And replace them with:
That’s it! This will solve the issue.
In your view controller you could make the request like this:
You could add parameters in the dictionary. The
OAUTH_CONSUMER_KEY
andOAUTH_CONSUMER_SECRET
must be replaced by the values you gathered in the first step.You could also do this in Swift. Just use a bridging header to import the AFNetworking files.
Many thanks to khanghoang for the breakthrough in AFOAuth1Client.
Adding answer to @Akilan Arasu for Swift solution to “List Products” in WooCommerce
Follow the first four steps of above solution and to list products from WooCommerce 5th step in swift will be