简体   繁体   English

iOS 相当于在 Android 中启动 Activity

[英]iOS equivalent of launching an Activity in Android

I just got done writing an Android Activity that allows other Activities to call it for some result (it's not intended to be a stand-alone Activity).我刚写完一个 Android 活动,它允许其他活动调用它以获得某些结果(它不是一个独立的活动)。 I'm now working on the equivalent iOS application and can't find any resources for how I would enable similar functionality on iOS.我现在正在研究等效的 iOS 应用程序,但找不到任何资源来说明如何在 iOS 上启用类似功能。

The situation: The tool I'm producing is intended to be used by other applications, rather than as a standalone application.情况:我正在制作的工具旨在供其他应用程序使用,而不是作为独立应用程序使用。 The thing is, the GUI that needs to be presented to the user is rather involved so I'd like to be able to provide the developer with a "all-in-one" package that they can simply launch and get results from.问题是,需要呈现给用户的 GUI 相当复杂,所以我希望能够为开发人员提供“一体化”package,他们可以简单地启动并从中获取结果。 Doing this in Android was very straight forward.在 Android 中执行此操作非常简单。 I simply wrote an Activity and instructed the developer to launch this Activity for result.我只是写了一个 Activity 并指示开发人员启动这个 Activity 以获得结果。 I've looked around and can't find a similar functionality to allow an iOS developer to do the same.我环顾四周,找不到类似的功能来允许 iOS 开发人员做同样的事情。 What would be the best way to go about doing this? go 关于这样做的最佳方法是什么?


I think part of the problem I'm having in finding resources is that I'm not entirely sure what what I'm making is called.我认为我在寻找资源时遇到的部分问题是我不完全确定我在做什么。 A library?图书馆? extension?扩大? plug-in?插入? I would think a library doesn't have a GUI and it seems extensions and plug-ins are made for an extensible application (that is, one in which the user can install the extension/plug-in).我认为库没有 GUI,并且似乎扩展和插件是为可扩展的应用程序(即用户可以安装扩展/插件的应用程序)制作的。

Your API could be à single call that would pop up a modal view.您的 API 可能是一个会弹出模式视图的单个调用。 A target and selector can be specified to receive an answer.可以指定目标和选择器来接收答案。 Supplying it to other developers means packing it into a "framework".将其提供给其他开发人员意味着将其打包到“框架”中。 I'm not sure if you can include resources.我不确定您是否可以包含资源。

There isn't really any equivalent.真的没有任何等价物。 The closest you can come is having the second application call UIApplication's openURL with a custom scheme that is listened to by your app, and then when your app is done it would do the same with a custom scheme that is listened to by the calling app.最接近的方法是让第二个应用程序使用您的应用程序侦听的自定义方案调用 UIApplication 的openURL ,然后当您的应用程序完成后,它会使用调用应用程序侦听的自定义方案执行相同的操作。

In practice, the iOS app would usually include the entire activity-equivalent as some sort of library, which at the high level would take the form of a UIViewController subclass that is presented modally and then calls a delegate method or completion selector of some sort on completion.在实践中,iOS 应用程序通常会包含整个活动等效项作为某种库,在高层将采用 UIViewController 子类的形式,该子类以模态方式呈现,然后调用委托方法或某种完成选择器完成。

iPhone development is a different design than Android development, so you may need to rethink what it is you are trying to do. iPhone 开发与 Android 开发的设计不同,因此您可能需要重新考虑您正在尝试做什么。

Most likely you will want to look at just including the code in each program, initially, just so you can get it testable, but that may not be the best solution.最初,您很可能只想在每个程序中包含代码,以便您可以测试它,但这可能不是最好的解决方案。

But, without knowing more details about what you are trying to do it is hard to give some suggestions as to better solutions.但是,如果不了解您正在尝试做的事情的更多细节,就很难就更好的解决方案提出一些建议。

For example, you may find LocalNotifications as one solution ( http://useyourloaf.com/blog/2010/7/31/adding-local-notifications-with-ios-4.html ), but again, it depends on what your needs are.例如,您可能会发现LocalNotifications作为一种解决方案( http://useyourloaf.com/blog/2010/7/31/adding-local-notifications-with-ios-4.html ),但同样,这取决于您的需求是。

I found that using local notifications to call a REST service, then to process it and decide if I need to inform the user was helpful, as a replacement for how I used Intents in the Android application.我发现使用本地通知调用 REST 服务,然后对其进行处理并决定是否需要通知用户是有帮助的,以替代我在 Android 应用程序中使用 Intents 的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM