1

正如标题所述,当我将更新推送到受人尊敬的店面时,我的 iOS 和 Android 用户报告他们的保存数据已被删除。游戏在应用程序加载和退出时正确保存和恢复数据。我没有更改任何保存信息位置或包名称...只是错误修复、构建、推送。

任何澄清都会有所帮助,或者我应该寻求建议的冗余数据备份方案,以确保最终用户体验从此不会受到负面影响。我还想更好地了解如何测试它,因为不允许发布包更新市场安装的应用程序。

var so:SharedObject = SharedObject.getLocal("storage"); 
var u:User;
if(so.data != null){
    u = so.data.user;
}

trace("Loading application...");

if(u != null){
    trace("LOADING SAVE DATA");
    user = u;
}else{
    trace("NO SAVE DATA EXISTS");
    user = new User();
}
4

1 回答 1

2

我已经发现了这个问题的原因,而且 Adob​​e 似乎也发现并修复了这个问题(从 AIR 3.5 开始)。https://bugbase.adobe.com/index.cfm?event=bug&id=3347676

SharedObject 存储在根据您的应用程序使用的 SWF 命名的目录中,因此如果您的应用程序在“myApp.swf”下运行,SharedObject 将存储在目录“myApp”中。如果您更改此 SWF 的名称(即 AIR 项目的相应 XML 构建表配置文件),任何后续构建都将其 SharedObjects 存储在新位置。

此错误中描述的问题专门针对 iOS,其中应用程序没有将 SharedObject 存储在如上所述的相应 SWF 位置,而是存储在项目 XML 构建表中的“文件名”属性表示的单独位置。

我还发现,Adobe 确实容忍在移动平台上使用 SharedObject 进行持久存储。

我已经为将来的版本保存冗余开发了一个简单的备份,以防将来的更新无法持久保存 SharedObject。

/** the last timestamp a deep save was completed */
private var mLastSave:Number = -1;


/**
 * save the state of the globals object and all of its
 * sub objects.
 * @warning
 * all objects must implement variables in a "public" state.
 * Private variables are not saved within the persistance manager
 */
public function save():void{
    var so:SharedObject = SharedObject.getLocal("storage");
    so.data.user = user;
    so.flush();
    saveDeep();
}


/**
 * Save the SharedObject to denoted mobile applicationStorageDirectory.
 */ 
public function saveDeep():void{
    // save on first application save or after
    // every 5 minutes
    if(mLastSave == -1 || mLastSave < getTime() + 300000){
        mLastSave = getTime();

        var file:File = File.applicationStorageDirectory.resolvePath("userSave");
        var fileStream:FileStream = new FileStream(); 
        fileStream.open(file, FileMode.WRITE);
        var ba:ByteArray = new ByteArray();
        ba.writeObject(user);
        fileStream.writeBytes(ba);
        fileStream.close();
    }   
}


/**
 * Load the application from the SharedObject be default
 * if the SharedObject DNE attempt to load from the 
 * applicationStorageDirectory, if neither exist
 * create new User object
 */ 
public function load():void{

    registerClassAlias("user", User);

    // Create/read a shared-object named "userData"
    var so:SharedObject = SharedObject.getLocal("storage"); 
    var u:User;
    if(so.data != null){
        u = so.data.user;
    }

    trace("Loading application...");

    if(u != null){
        trace("LOADING SAVE DATA");
        user = u;
    }else{
        trace("NO SAVE DATA EXISTS");
        var file:File = File.applicationStorageDirectory.resolvePath("userSave");
        if(file.exists){
            trace("Found userSave backup -attempting to load");
            var fileStream:FileStream = new FileStream(); 
            fileStream.open(file, FileMode.READ);
            var ba:ByteArray = new ByteArray();
            fileStream.readBytes(ba);
            fileStream.close();
            try{
                user = (ba.readObject() as User);
            }catch( e : EOFError ){
                trace("SharedObject did not exist, attempted userSave load, failed");
            }
        }else{          
            user = new User();
            trace("created New user...");
        }
    }
}
于 2013-05-29T14:23:45.587 回答