当所有场景都被消除时,如何选择在 iPadOS 上恢复哪个场景?
我有一个 iPad 应用程序,我开始支持多个窗口/场景。我有一种主窗口类型(例如 MainScene
),以及至少一种用于打开特定类型内容的辅助窗口类型(例如 DetailScene
)。
我尚未在 Info.plist
中声明我的场景类型。我已经实现了 application:configurationForConnectingSceneSession:options:
像这样:
-(UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options
{
NSUserActivity *activity = options.userActivities.anyObject;
NSString *activityType = activity.activityType;
if ([activityType isEqualToString:@"detailType"])
return [DetailSceneDelegate makeSceneConfiguration];
return [MainSceneDelegate makeSceneConfiguration];
}
假设我执行以下步骤:
- 第一次启动应用程序。我收到对
configurationForConnectingSceneSession
的调用,并且活动类型为nil
,因此它返回MainScene
。 - 打开一个新窗口以显示某些内容。它使用详细场景活动类型,因此
configurationForConnectingSceneSession
返回一个DetailScene
。创建新场景如下所示:
NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:@"detailType"];
activity.userInfo = @{@"content_id": @(contentRowId)};
[[UIApplication sharedApplication] requestSceneSessionActivation:nil userActivity:activity options:nil errorHandler:nil];
- 暂停应用程序并打开应用程序切换器。首先放弃(通过向上滑动)主窗口,然后放弃详细信息窗口。该应用程序现已被终止。
- 重新启动应用程序。
此时,我没有收到对configurationForConnectingSceneSession
的调用。我通过直接调用 DetailSceneDelegate
取回了细节场景,从其用户活动中恢复。
我的问题:在这种情况下如何控制恢复哪个场景?我希望我的主要场景能够回来。
消息、邮件和便笺都可以执行此操作。如果您打开“消息”并将对话拖到新窗口中,您会看到该对话的窗口,角落里有一个“完成”按钮,可以关闭该窗口。如果您使用“消息”执行上述步骤,您将重新启动到完整的“消息”视图。他们是否正在将详细视图转换为主视图?或者有没有办法告诉系统细节场景是次要的,不应该首先恢复,或者我应该被问到我想通过configurationForConnectingSceneSession恢复什么?还是别的什么?
I have an iPad app in which I'm starting to support multiple windows / scenes. I have one main window type, let's say MainScene
, and at least one secondary window type for opening specific types of content, say DetailScene
.
I have not declared my scene types in Info.plist
. I have implemented application:configurationForConnectingSceneSession:options:
like this:
-(UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options
{
NSUserActivity *activity = options.userActivities.anyObject;
NSString *activityType = activity.activityType;
if ([activityType isEqualToString:@"detailType"])
return [DetailSceneDelegate makeSceneConfiguration];
return [MainSceneDelegate makeSceneConfiguration];
}
Say I perform these steps:
- Launch app for the first time. I get a call to
configurationForConnectingSceneSession
, and the activity type isnil
so it returns aMainScene
. - Open a new window for some piece of content. That uses the detail scene activity type, so
configurationForConnectingSceneSession
returns aDetailScene
. Creating the new scene looks like this:
NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:@"detailType"];
activity.userInfo = @{@"content_id": @(contentRowId)};
[[UIApplication sharedApplication] requestSceneSessionActivation:nil userActivity:activity options:nil errorHandler:nil];
- Suspend the app and open the app switcher. Discard (by flicking up) first the main window and then the detail window. The app is now killed.
- Relaunch the app.
At this point I do not get a call to configurationForConnectingSceneSession
. I get the detail scene back, restored from its user activity, with calls straight to DetailSceneDelegate
.
My question: how do I control what scene gets restored in this situation? I want my main scene to come back.
Messages and Mail and Notes all do this. If you open Messages and drag a conversation out into a new window, you get a window for that conversation with a Done button in the corner that will dismiss the window. If you perform my steps above with Messages, you will relaunch to the full Messages view. Are they converting the detail view to a main view on the fly? Or is there a way to tell the system that the detail scene is secondary and should not be restored first, or that I should get asked what I want to restore via configurationForConnectingSceneSession
? Or something else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将其交叉发布到 Apple 开发者论坛 并从框架工程师那里得到了答案。答案是
UISceneActivationConditions
,设置为 属性。将canActivateForTargetContentIdentifierPredicate
设置为始终返回NO
:我在
UIWindowSceneDelegate
的scene:willConnectToSession:options:
实现中执行此操作代码> 实现。截至目前,在 Xcode 13.2 和 iOS 15.2 模拟器上,如果第二次启动(上面的步骤 4)是通过点击应用程序图标来启动的,则它可以工作,但如果是通过在 Xcode 中构建和运行来启动,则不行。我可能会对此提出反馈。
I cross-posted this to the Apple Developer forums and got an answer from a Framework Engineer. The answer is
UISceneActivationConditions
, set as a property onUIScene
. Set thecanActivateForTargetContentIdentifierPredicate
to always returnNO
:I do this in my implementation of
scene:willConnectToSession:options:
in myUIWindowSceneDelegate
implementation.As of current writing, on Xcode 13.2 and iOS 15.2 simulator, it works if the second launch (step 4 above) is via tapping the app icon, but not when it's via building and running in Xcode. I may file a feedback on this.