Auth.auth().signInAnonymously{result,errorin// User signed in}
Objective-C
[FIRAuthsignInAnonymouslyWithCompletion:^(FIRAuthDataResult*_Nullableresult,NSError*_Nullableerror){// User signed in}];
액세스 그룹의 모든 앱에서 동일한 현재 사용자를 사용할 수 있습니다.
Swift
varuser=Auth.auth().currentUser
Objective-C
FIRUser*user=FIRAuth.auth.currentUser;
비공유 키체인으로 다시 전환
인증 상태 공유를 중지하려면 액세스 그룹을 nil로 설정합니다.
Swift
do{tryAuth.auth().useUserAccessGroup(nil)}catchleterrorasNSError{print("Error changing user access group: %@",error)}
Objective-C
[FIRAuth.authuseUserAccessGroup:nilerror:nil];
로그인 방법을 사용하여 사용자로 로그인합니다. 다른 앱에서는 사용자 상태가 표시되지 않습니다.
Swift
Auth.auth().signInAnonymously{result,errorin// User signed in}
Objective-C
[FIRAuthsignInAnonymouslyWithCompletion:^(FIRAuthDataResult*_Nullableresult,NSError*_Nullableerror){// User signed in}];
로그인한 사용자를 공유 키체인으로 마이그레이션
이미 로그인한 사용자를 공유 상태로 마이그레이션하려면 다음 안내를 따르세요.
나중에 사용할 수 있도록 현재 사용자를 참조합니다.
Swift
varuser=Auth.auth().currentUser
Objective-C
FIRUser*user=FIRAuth.auth.currentUser;
(선택사항) 공유하려는 액세스 그룹의 인증 상태를 확인합니다.
Swift
letaccessGroup="TEAMID.com.example.group1"vartempUser:User?do{trytempUser=Auth.auth().getStoredUser(forAccessGroup:accessGroup)}catchleterrorasNSError{print("Error getting stored user: %@",error)}iftempUser!=nil{// A user exists in the access group}else{// No user exists in the access group}
Objective-C
NSString*accessGroup=@"TEAMID.com.example.group1";FIRUser*tempUser=[FIRAuthgetStoredUserForAccessGroup:accessGrouperror:nil];if(tempUser){// A user exists in the access group}else{// No user exists in the access group}
프로젝트 설정에서 이전에 설정한 액세스 그룹을 사용합니다.
Swift
do{tryAuth.auth().useUserAccessGroup(accessGroup)}catchleterrorasNSError{print("Error changing user access group: %@",error)}
[null,null,["최종 업데이트: 2025-08-16(UTC)"],[],[],null,["To share authentication states across multiple apps or extensions on Apple platforms, store\nthe authentication state in a shared keychain using [Keychain Services](https://developer.apple.com/documentation/security/keychain_services)\nand configure your apps to use the shared keychain.\n\nThis allows users to:\n\n- Sign in once and be signed in across all apps that belong to the same access group.\n- Sign out once and be signed out across all apps that belong to the same access group.\n\n| **Note:** Shared keychain does not automatically update users across apps in real time. If you make a change to a user in one app, the user must be reloaded in any other shared keychain apps before the changes will be visible.\n\nShare auth state between apps\n\nTo share auth state between apps:\n\n1. Set up an access group for your apps.\n\n You can use either a keychain access group or an app group. See [Sharing Access to Keychain Items Among a Collection of Apps](https://developer.apple.com/documentation/security/keychain_services/keychain_items/sharing_access_to_keychain_items_among_a_collection_of_apps)\n for details.\n\n To set up a keychain access group, do the following for each app:\n 1. In Xcode, go to **Project settings \\\u003e Capabilities**.\n 2. Enable Keychain Sharing.\n 3. Add a keychain group identifier. Use the same identifier for all of the apps you want to share state.\n2. In each app, set the access group to the keychain access group or app group\n you created in the previous step.\n\n Swift \n\n do {\n try Auth.auth().useUserAccessGroup(\"TEAMID.com.example.group1\")\n } catch let error as NSError {\n print(\"Error changing user access group: %@\", error)\n }\n\n Objective-C \n\n [FIRAuth.auth useUserAccessGroup:@\"TEAMID.com.example.group1\"\n error:nil];\n\n3. In at least one app, sign in a user with any sign in method.\n\n Swift \n\n Auth.auth().signInAnonymously { result, error in\n // User signed in\n }\n\n Objective-C \n\n [FIRAuth signInAnonymouslyWithCompletion:^(FIRAuthDataResult *_Nullable result,\n NSError *_Nullable error) {\n // User signed in\n }];\n\n The same current user is available in all apps in the access group. \n\n Swift \n\n var user = Auth.auth().currentUser\n\n Objective-C \n\n FIRUser *user = FIRAuth.auth.currentUser;\n\nSwitch back to an unshared keychain\n\n1. Set the access group to `nil` to stop sharing auth state.\n\n Swift \n\n do {\n try Auth.auth().useUserAccessGroup(nil)\n } catch let error as NSError {\n print(\"Error changing user access group: %@\", error)\n }\n\n Objective-C \n\n [FIRAuth.auth useUserAccessGroup:nil error:nil];\n\n2. Sign in a user with any sign in method. The user state will not be available\n to any other apps.\n\n Swift \n\n Auth.auth().signInAnonymously { result, error in\n // User signed in\n }\n\n Objective-C \n\n [FIRAuth signInAnonymouslyWithCompletion:^(FIRAuthDataResult *_Nullable result,\n NSError *_Nullable error) {\n // User signed in\n }];\n\nMigrate a signed-in user to a shared keychain\n\nTo migrate a user who's already signed in to a shared state:\n\n1. Make a reference to the current user for future use.\n\n Swift \n\n var user = Auth.auth().currentUser\n\n Objective-C \n\n FIRUser *user = FIRAuth.auth.currentUser;\n\n | **Note:** Switching from non-sharing to a shared keychain results in clearing the signed-in user. Switching from a shared to unshared keychain will not clear the signed-in user, even when no app uses that access group.\n2. (Optional) Check the auth state of the access group you want to share.\n\n Swift \n\n let accessGroup = \"TEAMID.com.example.group1\"\n var tempUser: User?\n do {\n try tempUser = Auth.auth().getStoredUser(forAccessGroup: accessGroup)\n } catch let error as NSError {\n print(\"Error getting stored user: %@\", error)\n }\n if tempUser != nil {\n // A user exists in the access group\n } else {\n // No user exists in the access group\n }\n\n Objective-C \n\n NSString *accessGroup = @\"TEAMID.com.example.group1\";\n FIRUser *tempUser = [FIRAuth getStoredUserForAccessGroup:accessGroup\n error:nil];\n if (tempUser) {\n // A user exists in the access group\n } else {\n // No user exists in the access group\n }\n\n3. Use an access group that you previously set in the project settings.\n\n Swift \n\n do {\n try Auth.auth().useUserAccessGroup(accessGroup)\n } catch let error as NSError {\n print(\"Error changing user access group: %@\", error)\n }\n\n Objective-C \n\n [FIRAuth.auth useUserAccessGroup:accessGroup error:nil];\n\n4. Update the current user.\n\n Swift \n\n Auth.auth().updateCurrentUser(user!) { error in\n // Error handling\n }\n\n Objective-C \n\n [FIRAuth.auth updateCurrentUser:user completion:^(NSError * _Nullable error) {\n // Error handling\n }];\n\n | **Note:** You will receive 2 notifications if you are listening to auth state changes on FIRAuth: first, it is triggered with nil (when switching to a new access group), and then triggered again with user (when `updateCurrentUser` is called). You can ignore these notifications.\n5. The user now can be accessed by other apps that have access to the same access group."]]