正如标题所述,我在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();
}
答案 0 :(得分:2)
我已经发现了这个问题的原因,似乎Adobe已经确定并修复了这个问题(从AIR 3.5开始)。 https://bugbase.adobe.com/index.cfm?event=bug&id=3347676
SharedObjects存储在根据应用程序使用的SWF命名的目录中,因此如果您的应用程序运行“myApp.swf”,则SharedObject将存储在“myApp”目录中。如果更改此SWF的名称(即AIR项目的相应XML构建表配置文件),则任何后续构建都会将其SharedObject存储在新位置。
此错误中描述的问题专门针对iOS表示,其中应用程序未将SharedObject存储在如上所述的相应SWF位置中,而是存储在项目的XML构建表中由“filename”属性表示的单独位置。
我还发现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...");
}
}
}