c# - C# 示例中的 GKScore ReportScores 方法

标签 c# ios xamarin.ios xamarin

谁能告诉我如何使用 C# 编写 ReportScores 示例?我发现了很多关于它是如何用 objective-C 而不是 C# 编写的例子,而且转换器很贵。 我一直在使用旧的、现在已弃用的 GKScore ReportScore,并尝试迁移到新的 GKScore ReportScores。我在 ReportScores 方法的 Action 参数上苦苦挣扎。这是我的代码:

GKScore scoreReporter = new GKScore (category);
scoreReporter.Value = score;
GKScore[] allScores = new GKScore[] { scoreReporter };
scoreReporter.ReportScores(allScores, new Action<NSError> ((error) => {

在最后一行编译时出错:

Error CS0176: Static member `MonoTouch.GameKit.GKScore.ReportScores 
(MonoTouch.GameKit.GKScore[], System.Action 
<MonoTouch.Foundation.NSError>)' 
cannot be accessed with an instance reference, 
qualify it with a type name instead 

如果我尝试先在这行之前:

Action<NSError> completionHandler = new Action<NSError> ();
scoreReporter.ReportScores(allScores, completionHandler

它在第一行出错:

method name expected 

如果我尝试从“new Action()”中删除“new”,它会出错:

Error CS0119: Expression denotes a type', where avariable', value' ormethod group' was expected

我应该如何用 C# 编写它!?

谢谢

最佳答案

没关系,我找到了答案。我最终这样做了:

GKScore scoreReporter = new GKScore (category);
scoreReporter.Value = score;
GKScore[] allScores = new GKScore[] { scoreReporter };
GKScore.ReportScores(allScores, (x) => {
    if(x == null){
        new UIAlertView ("Score reported", "Score Reported successfully", null, "OK", null).Show ();
    }
    else{
        new UIAlertView ("Score Reported Failed", "Score Reported Failed", null, "OK", null).Show ();
    }
    NSThread.SleepFor(1);
});

关于c# - C# 示例中的 GKScore ReportScores 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28127574/

相关文章:

C# 等到条件为真

ios - 如何使用 UIImagePickerController 或其他替代方法访问原始视频?

ios - 从另一个类更改按钮的状态

ios - 如何使用 Xamarin iOS 在 View Controller 启动时在 PSPDFKIT 中显示注释工具栏

ios - Windows 中 VS2017 上的 Xamarin iOS 模拟器显示黑屏

c# - Xamarin.iOS 版本 Appstore 应用程序中的人类可读异常处理

c# - 对象引用静态成员垃圾处理

c# - Unity registerType 泛型参数的多态解析

c# - WebMethod 在参数中接收 null

ios - 我存储的钥匙串(keychain)数据是否仅限于我的应用程序?