简体   繁体   English

NSUserDefaults不保存在詹金斯模拟器上的内存中

[英]NSUserDefaults not saving in memory in simulator on Jenkins

I'm having this odd situation where the NSUserDefaults works fine on real devices, but not on the simulators of one particular mac we have. 我遇到这种奇怪的情况,其中NSUserDefaults可以在实际设备上正常运行,但不能在我们拥有的特定Mac的模拟器上运行。

registerDefaults works fine: registerDefaults可以正常工作:

NSUserDefaults.standardUserDefaults().registerDefaults(["Default1": 3, "Default2: false])

If I run NSUserDefaults.standardUserDefaults().dictionaryRepresentation() , these default values were included in the dictionary. 如果我运行NSUserDefaults.standardUserDefaults().dictionaryRepresentation() ,则这些默认值将包含在字典中。

However, setObject doesn't work 但是, setObject不起作用

NSUserDefaults.standardUserDefaults().setObject("abc", for Key: "ABC")
NSUserDefaults.standardUserDefaults().synchronize()

NSUserDefaults.standardUserDefaults().objectForKey("ABC") will always return nil on simulator. NSUserDefaults.standardUserDefaults().objectForKey("ABC")在模拟器上始终返回nil。

The mac has this problem is running El Capitan as a Jenkins CI Server (as Launch Agent), and I've tried to run the app on different versions of simulators (9.2, 8.4...etc) without any luck so far. Mac出现了这个问题,将El Capitan作为Jenkins CI Server(作为启动代理)运行,并且到目前为止,我尝试在不同版本的模拟器(9.2、8.4 ...等)上运行该应用程序。 Any thoughts? 有什么想法吗?

We've run into a similar situation ourselves, and before we went for a full on reinstall of the OS ( El Capitan ), we decided to try just creating a new user Jenkins2 as a proper real user, that lives in /Users/Jenkins2 , rather than the *nux-style install that lived in /Users/Shared/Jenkins . 我们自己也遇到过类似情况,在完全重新安装操作系统( El Capitan )之前,我们决定尝试创建一个新用户Jenkins2作为适当的真实用户,该用户位于/Users/Jenkins2 ,而不是/Users/Shared/Jenkins的* nux风格的安装。 After working through a lot of the kinks that came with permission changing, and moving files, this solved the problem for us. 解决了权限更改和文件移动带来的许多麻烦之后,这为我们解决了问题。

Versions: OSX El Capitan , Jenkins v. 1.652 and XCode 7.2.1 . 版本:OSX El Capitan ,Jenkins 1.652和XCode 7.2.1

If you're at your wits end, I'd suggest to try get a simple repro project that definitely doesn't work under Jenkins, and then verify it also doesn't work outside of Jenkins, in XCode, but when logged in as the Jenkins user. 如果您不知所措,我建议尝试使用一个简单的repro项目,该项目在Jenkins下绝对不起作用,然后在XCode中验证它是否在Jenkins之外也不起作用,但是当以Jenkins用户。 If so, it's likely you're hitting the same problem as us. 如果是这样,则可能是您遇到了与我们相同的问题。 Create a new user, in the default Mac way, and try that same project there. 以默认的Mac方式创建一个新用户,并在那里尝试相同的项目。 If that's a satisfiable solution to you, move all the Jenkins setup to that new user, and delete the old. 如果这是您可以满足的解决方案,请将所有Jenkins设置移至该新用户,然后删除旧用户。 That's what we've ended up doing, and we haven't had an issue since. 这就是我们最终要做的,此后就再也没有问题了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM