首页 \ 问答 \ 在WatchOS2上永久存储少量数据(NSMutableDictionary)的最佳实践(Best practice to store a small amount of data (NSMutableDictionary) permanent on the WatchOS2)

在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
更新时间:2022-05-21 17:05

最满意答案

@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. ...
  • 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 ...
  • 我发现问题问题是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或运行 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)