小编mah*_*gde的帖子

如何在启用协程的改造界面中重试 API 调用

我有一个用例,每当 API 调用中发生诸如互联网丢失或未知错误之类的一般错误时,需要显示带有重试按钮的错误 UI。当用户按下重试之前失败的 API 时,应该调用并恢复用户流程。

迁移协程方法前的API接口:

 interface TodoService {
    @POST("todo/create")
   fun createTodo(@Body request: TodoRequest): Call<TodoResponse>
}
Run Code Online (Sandbox Code Playgroud)

API客户端:

    fun <T> fetch(call: Call<T>, completion: (result: NetworkBoundResource<T>) -> Unit) {
   
    call.enqueue(object : Callback<T> {
        override fun onFailure(call: Call<T>, t: Throwable) {
            // I have the mechanism save call object and completion and show error UI
            // when user press retry fetch(call.clone(), completion
        }

        override fun onResponse(call: Call<T>, response: Response<T>) {

        }
    })
}
Run Code Online (Sandbox Code Playgroud)

在将改造接口迁移到协程挂起方法之前,这不是问题。因为我可以克隆改造调用对象(call.clone())并重试 API 调用,如代码注释中所述。

迁移协程方法后的API接口:

interface TodoService { …
Run Code Online (Sandbox Code Playgroud)

android kotlin retrofit2 kotlin-coroutines

6
推荐指数
1
解决办法
2569
查看次数

ContextAction MenuItem图标未在Xamarin.Forms基于PCL的解决方案的iOS平台中显示

嗨,我正在使用Xamarin.Forms基于PCL的解决方案开发应用程序.对于我的应用程序,我需要Listview ViewCell Contextaction.我引用了这个文档来添加contextActions.当我在android中运行它时,图标正在显示.但在iOS中它不起作用.

Xaml代码

 <ViewCell.ContextActions>
    <MenuItem Text="Edit" x:Name="MenuEdit" />
    <MenuItem Clicked="OnDeleteMenu" Icon="dustbin.png" Text="Delete" IsDestructive="true" 
        CommandParameter="{Binding .}" />
  </ViewCell.ContextActions> 
Run Code Online (Sandbox Code Playgroud)

请任何人提供解决方案或相关来源.

listview xamarin.ios xamarin.android xamarin xamarin.forms

5
推荐指数
1
解决办法
3709
查看次数

如何使用 ARKit 和 RealityKit 检测二维图像

我想使用ARKitRealityKit检测 2D 图像。我不想使用 SceneKit,因为很多实现都基于 RealityKit。我在 RealityKit 上找不到任何检测图像的示例。我参考了苹果的https://developer.apple.com/documentation/arkit/detecting_images_in_an_ar_experience示例代码。它使用 Scenekit 和ARSCNViewDelegate

let arConfiguration = ARWorldTrackingConfiguration()
arConfiguration.planeDetection = [.vertical, .horizontal]
arConfiguration.isLightEstimationEnabled = true
arConfiguration.environmentTexturing = .automatic

if let referenceImages = ARReferenceImage.referenceImages(inGroupNamed: "sanitzer", bundle: nil) {
    arConfiguration.maximumNumberOfTrackedImages = 1
    arConfiguration.detectionImages = referenceImages
}
self.session.run(arConfiguration, options: [.resetTracking, .removeExistingAnchors])
Run Code Online (Sandbox Code Playgroud)

我已实施ARSessionDelegate但无法检测图像?

func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
    //how to capture image anchor?
}   
func session(_ session: ARSession, didUpdate anchors: [ARAnchor]) {
    //how to capture image anchor? …
Run Code Online (Sandbox Code Playgroud)

augmented-reality swift arkit arimageanchor realitykit

2
推荐指数
1
解决办法
598
查看次数