ios macos_如何使用流构建跨平台的ios和macos聊天应用程序

ios macos

Apple’s recent release of Mac Catalyst makes it possible for iOS and macOS apps to share mostly the same native codebase. While in the past, a desktop and mobile cross-platform codebase commonly meant a web app packaged in a portable format, now it can be achieved with native code just as quickly. That means less time and money spent on development and more consistent, performant experience for users.

苹果公司最近发布的Mac Catalyst使iOS和macOS应用程序可以共享几乎相同的本机代码库。 过去,台式机和移动跨平台代码库通常是指以可移植格式打包的Web应用程序,现在可以使用本机代码同样快地实现它。 这意味着更少的时间和金钱用于开发,并且为用户提供了更一致的性能体验。

Now it’s incredibly simple to start building a native Mac app from your current iPad app. With Mac Catalyst, your apps share the same project and source code so you can efficiently convert your iPad app’s desktop-class features, and add more just for Mac. Deliver your new Mac app to an engaged audience of over 100,000,000 active Mac users.

现在,从您当前的iPad应用程序开始构建本机Mac应用程序非常简单。 使用Mac Catalyst,您的应用程序共享相同的项目和源代码,因此您可以有效地转换iPad应用程序的桌面类功能,并仅为Mac添加更多功能。 将您的新Mac应用交付给超过1亿活跃Mac用户的参与受众。

Apple Developer Portal: Bring Your iPad App to Mac

Apple Developer Portal:将您的iPad应用程序带到Mac

Stream Chat’s Swift SDK is fully compatible with Mac Catalyst, which means the chat experience that you build for iOS can easily transfer to macOS. Let’s take a look into what you can expect from this compatibility.

Stream Chat的Swift SDK与Mac Catalyst完全兼容,这意味着您为iOS构建的聊天体验可以轻松地转移到macOS。 让我们来看看这种兼容性可以带来什么。

UI组件 (UI Components)

The Stream Chat SDK comes with all the UI Components to get your app built in minutes. They translate seamlessly between iOS and macOS with minor changes in behavior for accommodating the user experience expected in each platform.

Stream Chat SDK随附了所有UI组件,可在数分钟内构建您的应用程序。 它们在iOS和macOS之间无缝转换,并且行为发生了细微变化,以适应每个平台上预期的用户体验。

Image for post

By using UISplitViewController, you can fit the channels and the chat screen in the same window, taking advantage of the larger screen. This usage is included in the sample app found in the stream-chat-swift repository.

通过使用UISplitViewController ,您可以利用较大的屏幕在同一窗口中容纳频道和聊天屏幕。 这种用法包含在stream-chat-swift存储库中的示例应用程序中。

上下文菜单 (Context Menu)

Long pressing a message on iOS blurs the background and shows a context menu with a set of actions that you can perform. On macOS, this translates to a control-click, which shows a typical macOS-looking context menu with the same set of options.

在iOS上长按一条消息会使背景模糊,并显示上下文菜单以及您可以执行的一组操作。 在macOS上,这转换为单击控制键,这显示了具有相同选项集的典型macOS外观上下文菜单。

Image for post

Each platform has a different set of guidelines, and some elements may vary a lot in the way they’re accessed and presented. For example, see Apple’s Human Interface Guidelines page on context menus for iOS and the macOS version of it.

每个平台都有一套不同的指南,某些元素的访问和呈现方式可能会有很大不同。 例如,请参阅iOS的上下文菜单及其macOS版本上的Apple的人机界面指南页面。

附件上传中 (Uploading Attachments)

Another Stream Chat functionality that translates from iOS to macOS is picking and uploading attachments. On both iOS and macOS, you can upload pictures from your gallery, though the UI differs quite a bit.

从iOS转换为macOS的另一种Stream Chat功能是选择和上传附件。 在iOS和macOS上,您都可以从图库中上传图片,尽管UI有所不同。

Image for post

The macOS version of taking a picture or recording a video will present a UI similar to that of Photo Booth, and the file browser will give you access to the whole collection of files in your Mac, instead of only the iCloud drive as is the case on iOS.

拍摄照片或录制视频的macOS版本将呈现类似于Photo Booth的UI,并且文件浏览器将使您可以访问Mac中的整个文件集合,而不仅仅是访问iCloud驱动器在iOS上。

All of this is the same iOS code running, and macOS takes care of turning those elements into natural macOS elements.

所有这些都是在运行相同的iOS代码,并且macOS负责将这些元素转换为自然的macOS元素。

推送通知 (Push Notifications)

Push notifications will also carry over seamlessly with the same configuration you use for iOS.

推送通知还将以与iOS相同的配置无缝地保留。

Image for post
Image for post

Xcode gives you the option to use the same Bundle ID for the iOS and macOS apps. If your app already supports notifications, there’s no additional setup that you need to do for the macOS version, and the way you register devices for push notifications with the Stream Chat SDK is also the same.

Xcode为您提供了为iOS和macOS应用程序使用相同的Bundle ID的选项。 如果您的应用程序已经支持通知,则无需为macOS版本进行其他设置,并且使用Stream Chat SDK为推送通知注册设备的方式也相同。

低级客户 (Low-Level Client)

The basis of the Stream Chat SDK is the low-level client. It communicates with Stream Chat’s API and provides the data to be displayed by the UI components. It’s fully compatible between iOS and macOS, and you can use it directly if you need more control.

流聊天SDK的基础是低级客户端。 它与Stream Chat的API通信,并提供要由UI组件显示的数据。 它与iOS和macOS完全兼容,如果需要更多控制,可以直接使用它。

和更多 (And more)

In theory, with Catalyst, any code you write for iOS should translate to macOS in some way or another. If you find a place where it isn’t working, you can quickly write custom code to fill that gap.

从理论上讲,使用Catalyst,您为iOS编写的任何代码都应以某种方式转换为macOS。 如果您发现一个无法正常工作的地方,则可以快速编写自定义代码来弥补这一空白。

https://gist.github.com/cardoso/1387827c9ffbf9fef74cf01865f8a2f9

https://gist.github.com/cardoso/1387827c9ffbf9fef74cf01865f8a2f9

Mac Catalyst is a rapidly evolving framework, and the same is true for Stream Chat. The team is making sure the code remains fully compatible and that you can build excellent chat experiences on iOS and macOS.

Mac Catalyst是一个快速发展的框架,Stream Chat也是如此。 团队将确保代码保持完全兼容,并且您可以在iOS和macOS上建立出色的聊天体验。

入门 (Getting Started)

To get started building your cross-platform iOS and macOS chat application, the best place to start is the Stream Chat iOS/Swift tutorial.

要开始构建跨平台的iOS和macOS聊天应用程序,最好的起点是Stream Chat iOS / Swift教程

After you’ve started with your chat app, and all your code and other dependencies are compatible with Mac Catalyst, all you need to do is to select Mac as a device in Deployment Info in your primary target.

在开始使用聊天应用程序并且所有代码和其他依赖项都与Mac Catalyst兼容之后,您要做的就是在主要目标的“部署信息”中选择Mac作为设备。

Image for post

PS: If you want to support file uploading, make sure to add a BOOL entry for “com.apple.security.files.user-selected.read-only” with value YES to the .entitlements file, otherwise the app will crash when opening the file browser.

PS:如果要支持文件上传,请确保为.entitlements文件添加值为YES的“ com.apple.security.files.user-selected.read-only” BOOL条目,否则应用程序将在崩溃时崩溃打开文件浏览器。

Thanks for reading and happy coding!

感谢您的阅读和愉快的编码!

Originally published at https://getstream.io.

最初发布在 https://getstream.io

翻译自: https://medium.com/swlh/how-to-build-a-cross-platform-ios-and-macos-chat-app-using-stream-fa2bc7ecc6aa

ios macos

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值