Google Play Achievement 离线解锁和同步

Google Play Achievement offline unlock and sync

Google 播放文档指出:

An achievement can be unlocked offline. When the game comes online, it syncs with the Google Play games services to update the achievement's unlocked state.

我尝试使用以下方法离线解锁成就:

Games.Achievements.unlock(mGoogleApiClient, achievementID);

但是,我收到以下错误:

java.lang.IllegalStateException: GoogleApiClient is not connected yet. at com.google.android.gms.internal.jx.a(Unknown Source) at com.google.android.gms.common.api.c.b(Unknown Source) at com.google.android.gms.games.internal.api.AchievementsImpl.unlock(Unknown Source)

为了防止这种情况,我用连接检查包装了解锁语句:

if (mGoogleApiClient.isConnected()) {
        Games.Achievements.unlock(mGoogleApiClient, achievementID);
}

这是Google Play Games:

提供的示例中使用的解决方案
 if (mGoogleApiClient.isConnected()) {
      // unlock the "Trivial Victory" achievement.
      Games.Achievements.unlock(mGoogleApiClient,
          getString(R.string.achievement_trivial_victory));
 }

这解决了错误问题。但是,我不知道这如何确保成就在设备联机时成功脱机解锁并同步,正如我在上面引用的文档中所保证的那样。在我看来,解锁事件将被简单地忽略,因为离线时 mGoogleApiClient.isConnected() returns false 并且 Google Play Games 无法知道该成就已离线解锁一次它上线,因为没有关于解锁事件的信息离线存储。 (在"if"块语句后没有"else"块语句,处理离线成就解锁)

我错过了什么吗?开发者是否有责任在设备离线时存储有关成就解锁的信息,然后在设备上线时告诉 Google Play 解锁成就?

缺少的 link 是您可以在离线时拨打 mGoogleApiClient.connect() - Google Play Games 即使在离线时也会 连接,让您调用 unlock() 和任何其他 API。