diff --git a/packages/console/src/assets/docs/tutorial/integrate-sdk/ios.mdx b/packages/console/src/assets/docs/tutorial/integrate-sdk/ios.mdx index 239379e3b..40461693d 100644 --- a/packages/console/src/assets/docs/tutorial/integrate-sdk/ios.mdx +++ b/packages/console/src/assets/docs/tutorial/integrate-sdk/ios.mdx @@ -2,10 +2,11 @@ import UriInputField from '@mdx/components/UriInputField'; import Step from '@mdx/components/Step'; import Tabs from '@mdx/components/Tabs'; import TabItem from '@mdx/components/TabItem'; +import Alert from '@/components/Alert'; props.onNext(1)} @@ -23,17 +24,24 @@ We do not support **Carthage** and **CocoaPods** at the time due to some technic
Carthage - Carthage needs a `xcodeproj` file to build, but `swift package generate-xcodeproj` will report a failure since we are using binary targets for native social plugins. We will try to find a workaround later. + +Carthage [needs a `xcodeproj` file to build](https://github.com/Carthage/Carthage/issues/1226#issuecomment-290931385), but `swift package generate-xcodeproj` will report a failure since we are using binary targets +for native social plugins. We will try to find a workaround later. +
CocoaPods - CocoaPods does not support local dependency and monorepo, thus it's hard to create a `.podspec` for this repo. + +CocoaPods [does not support local dependency](https://github.com/CocoaPods/CocoaPods/issues/3276) and monorepo, thus it's hard to create a `.podspec` for this repo. +
+ props.onNext(2)} @@ -63,20 +71,30 @@ let config = try? LogtoConfig( ``` + props.onNext(3)} > -First, let’s configure your redirect URI +### Configure Redirect URI + +First, let’s configure your redirect URI scheme. E.g. `logto://callback` + + The Redirect URI in iOS SDK is only for internal use. There's NO NEED to add a Custom URL Scheme until a connector asks. + + +Go back to Xcode, use the following code to implement sign-in: + ```swift do { - try await client.signInWithBrowser(redirectUri: "") + try await client.signInWithBrowser(redirectUri: "logto://callback") print(client.isAuthenticated) // true } catch let error as LogtoClientErrors.SignIn { // error occured during sign in @@ -84,6 +102,7 @@ do { ``` + props.onNext(4)} > -Calling `.signOut()` will clean all the Logto data in Keychain, if it has. +Calling `.signOut()` will clean all the Logto data in Keychain, if they exist. ```swift await client.signOut() ``` + -- [SDK Documentation](https://link-url-here.org) -- [OIDC Documentation](https://link-url-here.org) -- [Calling API to fetch accessToken](https://link-url-here.org) +- [Customize sign-in experience](https://docs.logto.io/docs/recipes/customize-sie) +- [Enable SMS or email passcode sign-in](https://docs.logto.io/docs/tutorials/get-started/enable-passcode-sign-in) +- [Enable social sign-in](https://docs.logto.io/docs/tutorials/get-started/enable-social-sign-in) +- [Protect your API](https://docs.logto.io/docs/recipes/protect-your-api) diff --git a/packages/console/src/assets/docs/tutorial/integrate-sdk/ios_zh-cn.mdx b/packages/console/src/assets/docs/tutorial/integrate-sdk/ios_zh-cn.mdx new file mode 100644 index 000000000..445f8a03c --- /dev/null +++ b/packages/console/src/assets/docs/tutorial/integrate-sdk/ios_zh-cn.mdx @@ -0,0 +1,136 @@ +import UriInputField from '@mdx/components/UriInputField'; +import Step from '@mdx/components/Step'; +import Tabs from '@mdx/components/Tabs'; +import TabItem from '@mdx/components/TabItem'; +import Alert from '@/components/Alert'; + + props.onNext(1)} +> + +使用如下的 URL 将 Logto SDK 添加至 Swift Package Manager 的依赖中。 + +```bash +https://github.com/logto-io/swift.git +``` + +从 Xcode 11 开始,无需任何额外工具你就可以 [引入一个 Swift package](https://developer.apple.com/documentation/swift_packages/adding_package_dependencies_to_your_app)。 + +因为一些技术原因,我们暂时不支持 **Carthage** 和 **CocoaPods**。 + +
+ Carthage + +Carthage [需要创建一个 `xcodeproj` 文件才能编译](https://github.com/Carthage/Carthage/issues/1226#issuecomment-290931385),但由于我们内置了一些社交插件所用到的二进制目标文件,导致使用 `swift package generate-xcodeproj` 命令时报错。我们会继续努力寻求解决方案。 + +
+ +
+ CocoaPods + +CocoaPods [不支持本地依赖](https://github.com/CocoaPods/CocoaPods/issues/3276) 和 monorepo,所以要在此工程创建 `.podspec` 文件使用 Cocoapods 的话将非常困难。 + +
+ +
+ + props.onNext(2)} +> + +
+
+{`import Logto
+
+let config = try? LogtoConfig(
+  endpoint: "${props.endpoint}",
+  appId: "${props.appId}",
+)
+let logtoClient = LogtoClient(useConfig: config)`}
+
+
+ +我们默认会把例如 ID Token 和 Refresh Token 这样的凭据存储在 Keychain 中,如此一来用户在重新打开应用的时候无需再次登录。 + +如果需要禁用这个行为,可将 `usingPersistStorage` 设置成 `false`: + +```swift +let config = try? LogtoConfig( + // ... + usingPersistStorage: false +) +``` + +
+ + props.onNext(3)} +> + +### 配置 Redirect URI + +首先,我们来配置你的 redirect URI scheme。例如 `logto://callback` + + + + + iOS SDK 中的 Redirect URI 仅用于内部。除非连接器有要求,否则 无需 在项目中添加 Custom URL Scheme。 + + +回到 Xcode,使用如下代码实现登录: + +```swift +do { + try await client.signInWithBrowser(redirectUri: "logto://callback") + print(client.isAuthenticated) // true +} catch let error as LogtoClientErrors.SignIn { + // 登录过程中有错误发生 +} +``` + + + + props.onNext(4)} +> + +调用 `.signOut()` 将清除 Keychain 中所有 Logto 的数据(如果有)。 + +```swift +await client.signOut() +``` + + + + + +- [自定义登录体验](https://docs.logto.io/zh-cn/docs/recipes/customize-sie) +- [启用短信或邮件验证码登录](https://docs.logto.io/zh-cn/docs/tutorials/get-started/enable-passcode-sign-in) +- [启用社交登录](https://docs.logto.io/zh-cn/docs/tutorials/get-started/enable-social-sign-in) +- [保护你的 API](https://docs.logto.io/zh-cn/docs/recipes/protect-your-api) + + diff --git a/packages/console/src/pages/Applications/components/Guide/index.tsx b/packages/console/src/pages/Applications/components/Guide/index.tsx index fb9678a88..baf50bcae 100644 --- a/packages/console/src/pages/Applications/components/Guide/index.tsx +++ b/packages/console/src/pages/Applications/components/Guide/index.tsx @@ -24,6 +24,7 @@ const Guides: Record JSX.Elemen react: lazy(async () => import('@/assets/docs/tutorial/integrate-sdk/react.mdx')), vue: lazy(async () => import('@/assets/docs/tutorial/integrate-sdk/vue.mdx')), vanilla: lazy(async () => import('@/assets/docs/tutorial/integrate-sdk/vanilla.mdx')), + 'ios_zh-cn': lazy(async () => import('@/assets/docs/tutorial/integrate-sdk/ios_zh-cn.mdx')), 'android_zh-cn': lazy( async () => import('@/assets/docs/tutorial/integrate-sdk/android_zh-cn.mdx') ),