在WatchOS2上永久存储少量数据(NSMutableDictionary)的最佳实践(Best practice to store a small amount of data (NSMutableDictionary) permanent on the WatchOS2)
借助WatchOS2的新架构,手表应用程序可以独立运行而无需连接到iPhone。 存储少量数据的最佳实践是什么(例如NSMutableDictionary),它通常存储在NSUserdefaults中。 NSUserdefaults不适用于WatchOS2。
具体:当应用程序第一次运行时,会收集一些数据,存储在iPhone上的NSUserdefaults中,然后通过WatchConnectivity传输到Apple手表。
如果用户下次在Apple手表上独立运行时,我需要检索数据。
With the new architecture of WatchOS2, watch apps can run stand alone without a connection to the iPhone. What would be the best practice to store a small amount of data (by example a NSMutableDictionary), which normally would be stored in the NSUserdefaults. NSUserdefaults is not working on WatchOS2.
Concrete: When the app runs for the first time some data are collected, stored in the NSUserdefaults on the iPhone and than transferred via WatchConnectivity to the Apple watch.
If the user runs the next time the app stand alone on the Apple watch I need that data ton be retrieved.
原文:https://stackoverflow.com/questions/32501964
最满意答案
@greenapps发现错误。 由于它是异步数据传输并且Arduino设备的时序未知,因此必须重复批量传输直到收到某些内容。 我在一些迭代中使用了for循环。 一旦批量转移的返回值与1不同,我就会退出循环并继续。
谢谢您的帮助
@greenapps found the error. Since it is an asynchronious data transfer and the timing of the Arduino device is not known, it is necessary to repeat the bulktransfer until something is received. I used a for loop with some iterations. As soon as the return value of the bulk transfer differs from one, I break out of the loop and continue.
Thanks for the help
相关问答
更多-
感谢Chris Stratton小费。 使用PARTIAL_WAKE_LOCK ,屏幕可以关闭,但CPU仍然在运行。 这适合我的应用程序。 我创建了一个快速的应用来测试这个: public class MainActivity extends Activity { PowerManager pm; PowerManager.WakeLock wl; @Override protected void onCreate(Bundle savedInstanceState) { ...
-
您可以使用任何类型的微控制器或CPU,只要它支持Usb,或者您可以使用ftdi适配器将UART或I2C或SPI .....转换为USB。 Arduion有一个atmel微控制器,内置ft232芯片。 You can use any kind of micro controllers or CPUs as long as it supports Usb or you can use a ftdi adapter to convert from UART or I2C or SPI ..... to USB. ...
-
蓝牙到Android到Arduino通信:有可能吗?(Bluetooth to Android to Arduino communication: Is It possible?)[2024-01-11]
Yepp兄弟,除了arduino之外我还可以使用其他开发板,但重要的是概念,所有开发板都是如此。 在我的项目中,我在Android移动设备和机器人之间创建了一个连接,然后通过App控制其移动,例如使用机器人手臂及其动作拾取对象。 Yepp bro it's possible i did with some other development board other than arduino but the important thing is concept and it's same for all de ... -
我想通过“读取SD卡文本文件”意味着将SD卡插入SD-USB适配器然后从中读取文件。 如果是这样,库中应该有一个名为testusbhostFAT的例子( 这里你会找到在线版本),他们在那里读取存储在FAT HDD中的文件(我认为SD-USB适配器被视为HDD或FDD)。 无论如何,他们明确地说 由于ATmega328p中有限的ram,这将不会运行Arduino Uno。 通过查看代码,你可能会设法在Uno上运行它,但是......好吧,可能它有点难。 再见 I suppose that by "readin ...
-
@greenapps发现错误。 由于它是异步数据传输并且Arduino设备的时序未知,因此必须重复批量传输直到收到某些内容。 我在一些迭代中使用了for循环。 一旦批量转移的返回值与1不同,我就会退出循环并继续。 谢谢您的帮助 @greenapps found the error. Since it is an asynchronious data transfer and the timing of the Arduino device is not known, it is necessary to r ...
-
通过USB主机检查来自arduino的数据到android(check the data coming from arduino to android via USB host)[2021-06-18]
我发现问题问题是android无法通过单个bulktransfer()函数调用读取arduino发送的整个数据(使用Serial.print()),所以我在while循环中进行bulktransfer()(或读取),然后我通过在readed数据中检测到每一个新行(“\ n”)时构建一个String来检查arduino发送的每个Sting I found the problem The problem is that android cannot read the whole data sent from a ... -
我想我找到的东西至少暂时起作用了: public void run(){ int i = 0; byte[] buffer = new byte[4]; byte[] finalBuffer = new byte[8]; byte[] sendBuffer = new byte[8]; int bytes = 0; while(true){ try{ ...
-
蓝牙连接是最好的,因为HC05适配器价格便宜,并且使用UART进行通信(与COM一样) Bluetooth connection is best, because HC05 adapters are dirt cheap and those use UART for communication (the same as com- port )
-
Arduino Due的原生USB端口能够支持高速USB(480 Mbps),默认情况下,它会在计算机上显示USB虚拟COM端口。 这是一个虚拟串行端口,因此您可以像USB驱动程序允许的那样快速地发送数据,并且您不受COM端口的虚拟“波特率”的限制,这是一个无关的设置。 我认为虚拟COM端口对你来说足够快,你应该在做一些更复杂的事情之前尝试一下。 要使用此端口, SerialUSB在Arduino程序中使用SerialUSB 。 该对象具有与Serial相同的接口。 如果您安装了Arduino IDE或运行 ...