Skip to content

Commit

Permalink
update swift readme doc (#106)
Browse files Browse the repository at this point in the history
* update iOS swift sample App doc to address package downloading issue.

---------

Co-authored-by: Bolin Liu <boliu@microsoft.com>
  • Loading branch information
BolinLiu and BolinLiu-ms committed Jul 8, 2024
1 parent cced405 commit 167c426
Showing 1 changed file with 83 additions and 32 deletions.
115 changes: 83 additions & 32 deletions samples/swift/face/FaceAnalyzerSample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,75 @@ In this sample, you will learn how to build and run the face liveness detection

## Set up the environment
1. If this is your first time using your Mac to develop, you should build a sample app from [About Me &#x2014; Sample Apps Tutorials | Apple Developer Documentation](https://developer.apple.com/tutorials/sample-apps/aboutme) and run it on your phone before you attempt to build the App here. This will help ensure that your developer environment has been setup properly.
1. If you have a valid Azure subscription that has been provisioned for Face API Liveness Detection, you can get the access token to access the release artifacts. More details can be found in [GET_FACE_ARTIFACTS_ACCESS](../../../../GET_FACE_ARTIFACTS_ACCESS.md).
1. To install the SDK packages for your iOS development Application in Xcode, here are ways through CocoaPods or Swift Package Manager:
2. If you have a valid Azure subscription that has been provisioned for Face API Liveness Detection, you can get the access token to access the release artifacts. More details can be found in [GET_FACE_ARTIFACTS_ACCESS](../../../../GET_FACE_ARTIFACTS_ACCESS.md).
3. To install the SDK packages for your iOS development Application in Xcode, here are ways through CocoaPods or Swift Package Manager:

- Prerequisite
- You may encounter error if your Xcode has never been configured to use Git LFS. If Git LFS is never installed on your machine, refer to [Git LFS official site](https://git-lfs.github.com/) for instructions on how to install.
- An example installation command in macOS is:
```
brew install git-lfs
```
- Make sure you initialize Git LFS after installation is done:
```
git lfs install
```
- You can verify your Git LFS installation by checking the version:
```
git lfs --version
```

- Swift Package Manager ([Swift.org - Package Manager](https://www.swift.org/documentation/package-manager/))

- This approach requires XCode recognize and execute `git-lfs` command. However, the execution of `git-lfs` may be impacted by your macOS [System Integrity Protection (SIP)](https://developer.apple.com/documentation/security/disabling_and_enabling_system_integrity_protection). First, please check whether SIP is enabled or not by running in your macOS Terminal:
```
csrutil status
```

- If SIP is not enabled, or you temporarily disabled it. You can run the following command to create symbolic link and make Xcode recognize the `git-lfs` command:

```sh
sudo ln -s $(which git-lfs) $(xcode-select -p)/usr/bin/git-lfs
```

- After you configured Git LFS successfully, use the following repository URLs in Swift Package Manager, one at a time:

```
https://msface.visualstudio.com/SDK/_git/AzureAIVisionCore.xcframework
```

```
https://msface.visualstudio.com/SDK/_git/AzureAIVisionFace.xcframework
````

- You will see a pop-up window asking for username and password. Make a random username and use the accessToken from previous step to be the password.

Note: the username is just a placeholder, and it can be any random string.

- Alternatively, if SIP is enabled or you cannot resolve Git LFS issue for Swift Package Manager, you can download the packages by cloning the source Git repositories directly.
- use the access token from [GET_FACE_ARTIFACTS_ACCESS](../../../../GET_FACE_ARTIFACTS_ACCESS.md) as a "password" to clone the following repositories, then manually copy the files to your project.
```
git clone https://username:{accessToken}@msface.visualstudio.com/SDK/_git/AzureAIVisionCore.xcframework
git clone https://username:{accessToken}@msface.visualstudio.com/SDK/_git/AzureAIVisionFace.xcframework
```

Note: "accessToken" is the only required parameter here.

- After cloning the repositories, you should see 'AzureAIVisionCore.xcframework' and 'AzureAIVisionFace.xcframework' as two separate folders in your local path. The frameworks you should use are located under the parent folders, like:
```
AzureAIVisionCore.xcframework/AzureAIVisionCore.xcframework
AzureAIVisionFace.xcframework/AzureAIVisionFace.xcframework
```
Ensure their disk size is larger than 100MB. If not, check your Git LFS installation and initialization, then run the following commands in each repository directory:
```
git lfs pull
```
- Open your Xcode project and navigate to Target -> General -> Frameworks, Libraries, and Embedded Content. Remove any existing Swift Package Manager dependencies for 'AzureAIVisionCore.xcframework' and 'AzureAIVisionFace.xcframework' if they are defined that way. Choose "Add Other", then "Add files", and add both frameworks from your cloned repositories path:
```
localPath\AzureAIVisionCore.xcframework\AzureAIVisionCore.xcframework
localPath\AzureAIVisionFace.xcframework\AzureAIVisionFace.xcframework
```
Mark them as "Embedded & Sign".

- CocoaPods ([CocoaPods Guides - Getting Started](https://guides.cocoapods.org/using/getting-started.html))
- Add the following lines to your project's Podfile. `'YourBuildTargetNameHere'` is an example target, and you should use your actual target project instead.
Expand All @@ -27,42 +94,26 @@ In this sample, you will learn how to build and run the face liveness detection
target 'YourBuildTargetNameHere' do
# add the pods here, optionally with version specification as needed
pod 'AzureAIVisionCore'
pod 'AzureAIVisionFace'
pod 'AzureAIVisionCore', '0.17.1-beta.1'
pod 'AzureAIVisionFace', '0.17.1-beta.1'
end
```
- For access authorization to the repos, the steps depend on your system Git and your security preferences.
- If you are using Git credential manager, you will be prompted for username and password. Make a random username and use the accessToken from previous step to be the password. Random username means a random string because it is not really taken in this case.
- If you are using Git credential manager, you will be prompted for username and password.
Note: the username is just a placeholder, and it can be any random string.
- To use [`http.extraHeader` approach of `git-config`](https://git-scm.com/docs/git-config/2.22.0#Documentation/git-config.txt-httpextraHeader), you need to convert the token to base64 format. Refer to [the **Use a PAT** section of this Azure DevOps documentation article](https://learn.microsoft.com/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=Linux#use-a-pat). Note that instead of using the git clone invocation as shown in the example, you should call:
```
git config --global http.https://msface.visualstudio.com/SDK.extraHeader="Authorization: Basic ${B64_PAT}"
MY_PAT=accessToken
HEADER_VALUE=$(printf "Authorization: Basic %s" "$MY_PAT" | base64)
git config --global http.https://msface.visualstudio.com/SDK.extraHeader "${HEADER_VALUE}"
```
- For other types of Git installation, refer to [the **Credentials** section of Git FAQ](https://git-scm.com/docs/gitfaq#_credentials).
- Swift Package Manager ([Swift.org - Package Manager](https://www.swift.org/documentation/package-manager/))
- Use the following repository URLs in Swift Package Manager, one at a time:

```
https://msface.visualstudio.com/SDK/_git/AzureAIVisionCore.xcframework
```

```
https://msface.visualstudio.com/SDK/_git/AzureAIVisionFace.xcframework
````

- You will see a pop-up window asking for username and password. Make a random username and use the accessToken from previous step to be the password. Random username means a random string because it is not really taken in this case.
- You may encounter error if your Xcode has never been configured to use Git LFS.
If Git LFS is never installed on your machine, refer to [Git LFS official site](https://git-lfs.github.com/) for instructions on how to install. To make Xcode recognize the `git-lfs` command, create symbolic link like so:

```sh
sudo ln -s $(which git-lfs) $(xcode-select -p)/usr/bin/git-lfs
```

- If the previous step failed with `ln: git-lfs: Operation not permitted`, your macOS version has [System Integrity Protection (SIP)](https://developer.apple.com/documentation/security/disabling_and_enabling_system_integrity_protection) enabled and configured to protect the Git executable shipped with Xcode toolchain. Use your security judgment or consult with your enterprise administrators, then temporarily disable SIP before reattempting to run the code above if this is acceptable for you, following instructions in the official article [Disabling and Enabling System Integrity Protection | Apple Developer Documentation](https://developer.apple.com/documentation/security/disabling_and_enabling_system_integrity_protection). Alternatively, you may prefer to use CocoaPods instead. This issue has been [reported to Apple](https://github.com/apple/swift-package-manager/issues/5351) and we are awaiting resolution.
1. [Refer to the API reference documentation](#api-reference-documentation) to learn more about our SDK APIs.
4. [Refer to the API reference documentation](#api-reference-documentation) to learn more about our SDK APIs.
## Next steps
Now that you have setup your environment you can either:
Expand All @@ -73,11 +124,11 @@ Now that you have setup your environment you can either:
## Build and run sample App
1. Download the sample App folder. Double click the .xcodeproj file. This will open the project in Xcode.
1. Add package dependency through Swift Package Manager, as mentioned before. You should add both AzureAIVisionFace.xcframework and AzureAIVisionCore.xcframework into the project.
1. Set the App bundle identifier and developer team in XCode per your needs.
1. Now attach your phone to the Mac. You should get prompt on the phone asking you to "Trust" the Mac. Enable the trust.
1. The phone should now show up in the Xcode top bar. Your iPhone name should be visible.
1. Now build and run the app.
2. Add package dependency through Swift Package Manager, as mentioned before. You should add both AzureAIVisionFace.xcframework and AzureAIVisionCore.xcframework into the project. If you failed to use Swift Package Manager to add the frameworks, Please consider using alternative ways like cloning the source Git repositories or CocoaPods in [Set up the environment](#set-up-the-environment).
3. Set the App bundle identifier and developer team in "XCode -> Targets -> Signing & Capabilities" using your Apple developer account information.
4. Now attach your phone to the Mac. You should get prompt on the phone asking you to "Trust" the Mac. Enable the trust.
5. The phone should now show up in the Xcode top bar. Your iPhone name should be visible.
6. Now build and run the app.
### Run the sample
Expand Down

0 comments on commit 167c426

Please sign in to comment.