Using iOS SDK
Users can use SDK in token- or AK/SK-based authentication mode. For details about how to obtain authentication messages, see Authentication. This section describes how to use SDK in token- and AK/SK-based modes.
Download OCR iOS SDK from https://developer.huaweicloud.com/en-us/sdk?OCR, and decompress it.
A user needs to apply for enabling the service before using it for the first time. For details about how to enable the service, click Subscribe. You only need to subscribe to OCR once.
AK/SK-based Authentication
This section uses ID Card OCR as an example to describe how to use SDK in AK/SK-based authentication mode.
- Obtain AK/SK. For details, see Authentication > AK/SK-based Authentication.
- Configure AK/SK of the iOS SDK.
Change the values of AK and SK of the akskOcrService function in the ViewController.m file of the demo project to the obtained AK/SK.
Figure 1 Modifying parameters in the ViewController.m file
- If you use a local image file for recognition, modify the image parameter in the akskOcrService function of the ViewController.m file. If you use the default image of the SDK, you do not need to modify the image path.
- Execute the akskOcrService function. If 200 is displayed on the console, the program is successfully executed. You can view the recognition result of ID Card OCR on the console.
{ "result": { "name": "xx", "sex": "sex recognized from the image", "ethnicity": "ethnicity recognized from the image", "birth": "1990-xx-xx", "address": "address recognized from the image", "number": "3892011990012xxxxx" } }
To call other OCR services, change the value of parameter uri of the akskOcrService function to the specific URI. For the URI list, see Mappings Between Services and APIs.
Token-based Authentication
This section uses ID Card OCR as an example to describe how to use SDK in token-based authentication mode.
- Open the ViewController.m file. Change the values of username, password, and domainName in the tokenOcrService function to the actual username, password, and domain name registered with the system. If the user is not an IAM user, the domain name and username are the same. Figure 2 Changing the username, password, and domain name in the ViewController.m file
- Execute the code. The recognition result of ID Card OCR is displayed.
Status Code
For details about status code, see Status Code.
Error Code
For details about error code, see Error Code.
Last Article: Using Python SDK
Next Article: Using Android SDK
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.