首页 > 其他分享 >2023年XCode升级GameCenter必读

2023年XCode升级GameCenter必读

时间:2023-08-04 10:56:08浏览次数:32  
标签:Center entitlement import XCode GameCenter Game 2023 GKLocalPlayer

一、Game Center功能介绍

iOS中的 Game Center 是Apple提供的游戏中心服务,它具有以下核心功能:

  1. 玩家账号系统 - 提供玩家帐号系统,可以在不同游戏中使用统一的Game Center账号。
  2. 成就与排行榜 - 可以设置游戏内的成就系统,以及查看不同游戏的排行榜。
  3. 多人对战 - 支持通过WiFi或蓝牙进行的多人实时对战游戏。
  4. 社交功能 - 玩家可以在Game Center看到好友的游戏动态,还可以添加好友等。
  5. 云存储 - 提供基于iCloud的云存储功能,可以在不同设备上同步游戏进度。
  6. 登陆认证 - 提供了统一的Game Center登陆认证系统。

总之,Game Center为iOS游戏提供了丰富的社交、竞技功能,是游戏开发者可以直接集成使用的强大服务。它极大地丰富了iOS游戏的功能和体验。

二、iOS14升级

iOS14起,GameCenter升级了一些重要的代码,以积分榜为例:

旧代码,objective-c


#import "AppBasePageGame+GameCenter.h"
#import <GameKit/GameKit.h>

@implementation AppBasePageGame(GameCenter)

#pragma mark - GameCenter

//登录GameCenter:
-(void)goAuthenticate
{
    void (^authenticateHandler)(UIViewController *viewController, NSError *error) = ^(UIViewController *viewController, NSError *error) {
        if (viewController) {
            // 需要展示登录界面
            [self presentViewController:viewController animated:YES completion:nil];
        } else if (error) {
            // 验证错误
            NSLog(@"Authentication failed: %@", error.localizedDescription);
        } else {
            // 验证成功
            NSLog(@"Authentication succeeded");
        }
    };

    [[GKLocalPlayer localPlayer] setAuthenticateHandler:authenticateHandler];
}

//显示排行榜:
-(void)goShowTop
{

    if ([GKLocalPlayer localPlayer].isAuthenticated == NO) {
        NSLog(@"没有授权,无法获取展示中心");
        return;
    }

    GKGameCenterViewController *GCVC = [GKGameCenterViewController new];
    //跳转指定的排行榜中
    [GCVC setLeaderboardIdentifier:CONFIG_GAMECENTER_LEADERBOARD];
    //跳转到那个时间段
    NSString *type = @"all";
    if ([type isEqualToString:@"today"]) {
        [GCVC setLeaderboardTimeScope:GKLeaderboardTimeScopeToday];
    }else if([type isEqualToString:@"week"]){
        [GCVC setLeaderboardTimeScope:GKLeaderboardTimeScopeWeek];
    }else if ([type isEqualToString:@"all"]){
        [GCVC setLeaderboardTimeScope:GKLeaderboardTimeScopeAllTime];
    }
    GCVC.gameCenterDelegate = self;
    [self presentViewController:GCVC animated:YES completion:nil];

}

//上传分数:
-(void)goSubmitScore
{
    if ([GKLocalPlayer localPlayer].isAuthenticated == NO) {
        NSLog(@"没有授权,无法获取展示中心");
        return;
    }
    NSInteger userStar = [FrameUser getStar]*100;
    GKScore *scoreBoard = [[GKScore alloc] initWithLeaderboardIdentifier:CONFIG_GAMECENTER_LEADERBOARD];
    scoreBoard.value = userStar;
    [GKScore reportScores:@[scoreBoard] withCompletionHandler:^(NSError *error) {
        if (error) {
            // handle error
        }
    }];


}

//实现代理:
//接受关闭回调,非常重要
#pragma mark -  GKGameCenterControllerDelegate
- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController{
    [gameCenterViewController dismissViewControllerAnimated:YES completion:nil];
}
@end

iOS14后的代码,swift


import UIKit
import SpriteKit
import GameplayKit
import AVFoundation
import GoogleMobileAds
import GameKit
import SwiftUI

class GameViewController_GameCenter: GameViewController, GKGameCenterControllerDelegate {

    public var thisLeaderboardID="com.gpwzw.appChineseWordCross2.Score"

    override func viewDidLoad() {
        super.viewDidLoad()
        self.goGameCenterAuthenticate()

    }

    //登录GameCenter:
    func goGameCenterAuthenticate(){

        GKLocalPlayer.local.authenticateHandler = { gcAuthVC, error in
            if GKLocalPlayer.local.isAuthenticated {
                print("Authenticated to Game Center!")
            } else if let vc = gcAuthVC {
                self.present(vc, animated: true)
            }
            else {
                print("Error authentication to GameCenter: " +
                      "\(error?.localizedDescription ?? "none")")
            }
        }
    }

    //显示排行榜:
    func showGameCenterLeaderboard(){
        if GKLocalPlayer.local.isAuthenticated {
            let gameCenterViewLeaderBoard = GKGameCenterViewController(leaderboardID: thisLeaderboardID, playerScope: GKLeaderboard.PlayerScope.global, timeScope: GKLeaderboard.TimeScope.today)
            gameCenterViewLeaderBoard.gameCenterDelegate = self;
            self.present(gameCenterViewLeaderBoard,animated: true);
        }
        else{
            //self.goGameCenterAuthenticate();
        }
    }

    //上传分数:
    func postGameCenterLeaderboardAsync(_ score: Int) async{

        if GKLocalPlayer.local.isAuthenticated {
            Task{
                try await GKLeaderboard.submitScore(
                    score,
                    context: 0,
                    player: GKLocalPlayer.local,
                    leaderboardIDs: [thisLeaderboardID]
                )
            }
            print("Score submitted")
        }
    }

    //上传分数:
    func postGameCenterLeaderboardAll() async{

        let intLastStage = appDelegate.gameConfig.getConfigNumber(CONFIG_LAST_STAGE)
        let intScore = intLastStage * 100

        if GKLocalPlayer.local.isAuthenticated {
            Task{
                try await GKLeaderboard.submitScore(
                    intScore,
                    context: 0,
                    player: GKLocalPlayer.local,
                    leaderboardIDs: [thisLeaderboardID]
                )
            }
            print("Score submitted")
        }
    }

    //实现代理:
    //接受关闭回调,非常重要
    func gameCenterViewControllerDidFinish(_ gameCenterViewController: GKGameCenterViewController) {
        print("game center did finish")
        gameCenterViewController.dismiss(animated: true)
    }
}

三、2023年8月16日新规

苹果邮件原文

Starting August 16, 2023, new apps and app updates that offer Game Center features need to include the Game Center entitlement and have Game Center features configured in App Store Connect before you can submit them to the App Store. Existing apps on the App Store are not affected by this new requirement.



We noticed that although the apps listed below have Game Center features configured in App Store Connect, their latest binary delivery doesn’t include the Game Center entitlement. In your next app update, please update your binary to include the entitlement.



Name: 疯狂填字

......



How to add the entitlement

If you’re automatically signing your app with Xcode and haven’t enabled the Game Center capability, enabling Game Center automatically adds the entitlement to the entitlement plist. If Game Center is already enabled in Xcode, and the com.apple.developer.game-center entitlement isn’t in the entitlements plist, remove and re-enable the Game Center capability.



If you’re manually signing your app, make sure the capability is enabled in Certificates, Identifiers & Profiles, generate a new profile, and add the com.apple.developer.game-center entitlement directly to your entitlements plist.



Learn more about diagnosing issues with entitlements to verify the entitlement is included in your app. If your app isn’t taking advantage of Game Center, you should remove the capability in Xcode and App Store Connect.



If you have any questions, contact us.



Apple Developer Relations

这个简单,把以下内容加到 info 最后面即可

    <key>com.apple.developer.game-center</key>
    <true/>

标签:Center,entitlement,import,XCode,GameCenter,Game,2023,GKLocalPlayer
From: https://www.cnblogs.com/gpwzw/p/17605316.html

相关文章

  • 2023年CSPM-3国标项目管理中级证书含金量高吗?想考一个
    CSPM-3中级项目管理专业人员评价,是中国标准化协会(全国项目管理标准化技术委员会秘书处),面向社会开展项目管理专业人员能力的等级证书。旨在构建多层次从业人员培养培训体系,建立健全人才职业能力评价和激励机制的要求,培养我国项目管理领域复合型人才。  【证书含金量】 ·竞聘优先......
  • 2023年8月杭州/宁波/深圳CDGA/CDGP数据治理认证招生
    DAMA认证为数据管理专业人士提供职业目标晋升规划,彰显了职业发展里程碑及发展阶梯定义,帮助数据管理从业人士获得企业数字化转型战略下的必备职业能力,促进开展工作实践应用及实际问题解决,形成企业所需的新数字经济下的核心职业竞争能力。DAMA是数据管理方面的认证,帮助数据从业者提升......
  • 2023年8月杭州/宁波/深圳制造业产品经理NPDP认证招生
    产品经理国际资格认证NPDP是新产品开发方面的认证,集理论、方法与实践为一体的全方位的知识体系,为公司组织层级进行规划、决策、执行提供良好的方法体系支撑。  【认证机构】 产品开发与管理协会(PDMA)成立于1979年,是全球范围内产品开发与管理专业人士最杰出的倡导者,协助个人、企业......
  • 2023年下半年杭州/宁波/深圳软考信息系统项目管理师报名
    信息系统项目管理师是全国计算机技术与软件专业技术资格(水平)考试(简称软考)项目之一,是由国家人力资源和社会保障部、工业和信息化部共同组织的国家级考试,既属于国家职业资格考试,又是职称资格考试。信息系统项目管理师,属于软考三个级别中的“高级”。  【报考要求】 不设学历与资历......
  • 2023年9月杭州/宁波/深圳DAMA-CDGA/CDGP认证考试报名
    据DAMA中国官方网站消息,2023年度第三期DAMA中国CDGA和CDGP认证考试定于2023年9月23日举行。 报名通道现已开启,相关事宜通知如下: 考试科目: 数据治理工程师(CertifiedDataGovernanceAssociate,CDGA)数据治理专家(CertifiedDataGovernanceProfessional,CDGP) 考试时间: CDGA:2023......
  • Xcode Snippets 功能详解
    http://nshipster.com/xcode-snippets/iOSdevelopmentallbutrequirestheuseofXcode.Toitscredit,Xcodehasimprovedprettyconsistentlyoverthelastcoupleofyears.Sure, itstillhasits…quirks,buthey—thingscouldbe much,muchworse.Workingi......
  • 暑假集训D10 2023.8.3 补题
    D.DnDDice给出分别有不同个数的\(4,6,8,12,20\)面骰子,\(k\)面骰子的每个面的点数分别是\(1~k\).问用上所有骰子能组合出来的情况的概率从大到小排序,如果有相同的可能性的情况,按任意顺序即可.\(\operatorname{Solution}\)可以将骰子两两合并,合并后的骰子大小为\([m......
  • 2023.8.3
    早上起来买了17号的火车票18号早上就能到学校,时间过去好快啊不到两个星期就回去了,明天打算回去老家再玩玩,这边太无聊了,下午看了看新出的动漫,技术炸裂,真的是国产之光,晚上一如既往地写了会儿pta看了会儿java就睡了。......
  • 2023.8.3
    今天去看了花式栈溢出的stackpivoting,前面没怎么卡壳,倒是后面exp里payload的最后最后两部分汇编指令搞卡壳了,刚开始用本就没正式学过所以一知半解的汇编知识去分析,结果没分析出来,反而越分析越迷惑,无奈之下去查几个汇编指令的详细执行流程(如jmp,ret,leave),中间还又去找博客详细了解......
  • 2023.8.3 训练
    A有一个01矩阵,求最少取反若干矩阵,使得存在一条由左上到右下仅为0的路径,且只能向下向右走。设\(f(i,j,0/1)\)表示走到\((i.j)\),且那个点为0/1的最小值。用\(f(i-1,j),f(i,j-1)\)更新\(f(i,j)\)即可。B[AGC010C]Cleaning有一棵树,每次可以选择连接两个叶子的路......