Supporting iPadOS in Mobile SDK Apps
Mobile SDK 9.0
enhances the iPad customer experience. Landscape mode now functions as expected, and Mobile SDK now
supports multiple windows.
| Swift | Objective-C |
|---|---|
| AuthHelper | SFSDKAuthHelper |
To see the new methods in action, study the updated SceneDelegate class in the RestAPIExplorer sample app. The registerBlock(forCurrentUserChangeNotifications:) and
loginIfRequired(_:completion:) methods of the
AuthHelper class now accept a UIWindowScene argument.
In
the completion block of loginIfRequired(_:completion:), this sample app calls code that resets the
scene to its beginning state—in this case, an instance of RootViewController. The registerBlock(forCurrentUserChangeNotifications:completion:) completion
block first discards the view stack of the outgoing user, then resets the scene to
RootViewController. To support multiple
windows, copy these two calls into the scene(_:willConnectTo:_:) method of your Swift app’s SceneDelegate
instance. Replace the
existing AuthHelper.registerBlock(_:) call with the
scene-enabled version.
1func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
2 guard let windowScene = (scene as? UIWindowScene) else { return }
3 self.window = UIWindow(frame: windowScene.coordinateSpace.bounds)
4 self.window?.windowScene = windowScene
5
6 AuthHelper.registerBlock(forCurrentUserChangeNotifications: scene) {
7 self.resetViewState {
8 self.setupRootViewController()
9 }
10 }
11 self.initializeAppViewState()
12
13 AuthHelper.loginIfRequired(scene) {
14 self.setupRootViewController()
15 }
16}IDP Apps
Similarly to AppDelegate, SceneDelegate provides a method for opening URLs.
To support multiple windows, Mobile SDK
IDP client apps must use the scene delegate and pass in the scene’s persistent
identifier.
1func scene(_ scene: UIScene, openURLContexts URLContexts:1Set<UIOpenURLContext>) {
2
3 if let urlContext = URLContexts.first {
4 UserAccountManager.shared.handleIdentityProviderResponse(
5 from: urlContext.url,
6 with: [UserAccountManager.IDPSceneKey:
7 scene.session.persistentIdentifier])
8 }
9}AuthHelper Scene-Enabled Methods
The following AuthHelper methods are new
overloads that add a UIScene parameter to
existing methods.
- Swift
-
1func loginIfRequired(_ scene: UIScene, completion completionBlock: (() -> Void)?) 2 3func handleLogout(_ scene: UIScene, completion completionBlock: (() → Void)?) 4 5func registerBlock(forCurrentUserChangeNotifications scene: UIScene completion completionBlock: () → Void) 6 7func registerBlock(forLogoutNotifications scene:UIScene, completion completionBlock: () → Void) - Objective-C
-
1+ (void)loginIfRequired:(UIScene *)scene completion: 2 (nullable void (^)(void))completionBlock; 3 4+ (void)handleLogout:(UIScene *)scene completion: 5 (nullable void (^)(void))completionBlock; 6 7+ (void)registerBlockForCurrentUserChangeNotifications: 8 (UIScene *)scene completion:(void (^)(void))completionBlock; 9 10+ (void)registerBlockForLogoutNotifications: 11 (UIScene *)scene completion:(void (^)(void))completionBlock;