How to prevent iOS 14 Widget opening app and react to callback

时光毁灭记忆、已成空白 提交于 2021-02-04 07:38:25

问题


So, I already read several blogs, posts, and Apple's own Human Interface Guidelines that iOS 14 Widgets are NOT interactive, BUT: It's possible to pass a short link to the app when pressing on a target. Apple on its own says: "Small Widgets got one single tap target, Medium and Large Widgets got multiple tap targets". OK!

Now when you tap on these Targets the app is opening and the Widget is passing that short link to the App.

BUT, now my question, where Google says Idk:

Can I programmatically say "prevent opening app", when tapping on one of these buttons I've created in my Widget? It's just as easy as in Javascript: preventDefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault).

Is this possible? I just want to prevent the opening of the app and access that Tap-Target Callback that is triggered and process my stuff in SwiftUI.

Thanks a lot, guys :)


回答1:


Can I programmatically say "prevent opening app", when tapping on one of these buttons I've created in my Widget?

No, this is simply not possible (at least so far, in iOS 14).

By default whenever you tap on a Widget, the App will be opened. You can only specify deep links etc. but they'll always open the app.


I already read [...] that iOS 14 Widgets are NOT interactive

In this context interactive means that you can't touch/drag/interact with a Widget view like you'd normally do with a view in your main app (see Why do some views appear as a red no entry sign in widgets?).

Also, when you click on a Widget, you don't really interact with its view - you just open the app. As of iOS 14 you can't change it.



来源:https://stackoverflow.com/questions/65115917/how-to-prevent-ios-14-widget-opening-app-and-react-to-callback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!