草庐IT

ios - cloudkit 错误没有收到 Assets 的 authToken

coder 2023-09-13 原文

为什么我在运行以下代码时会出现此错误? :

"Internal Error" (1/1000); "No authToken received for asset"

我觉得跟最后一行的setObject代码有关系。

let documentsDirectoryPath:NSString = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString
var imageURL: URL!

let imageData = UIImageJPEGRepresentation(self.newImage, 1.0)
let path:String = documentsDirectoryPath.appendingPathComponent(self.newImage.description)
try? UIImageJPEGRepresentation(self.newImage, 1.0)!.write(to: URL(fileURLWithPath: path), options: [.atomicWrite])
imageURL = URL(fileURLWithPath: path)
try? imageData?.write(to: imageURL, options: [.atomicWrite])

let imageAsset:CKAsset? = CKAsset(fileURL: URL(fileURLWithPath: path))


curImages = record["Images"] as! [CKAsset]
curImages.append(imageAsset!)

print("saving image")
record.setObject(curImages as CKRecordValue?, forKey: "Images")

最佳答案

我也遇到过。它似乎是 cloudkit 中的一个错误,而且——据我所知——当您尝试重新使用“ Assets 创建链”的任何部分时,它就会发生。

换句话说,您有一些初始数据,您从该数据创建图像,将其写入文件,将该文件加载到 CKAsset,然后加载 CKAssetCKRecrod。在我的实验中,如果你重复使用这些组件中的任何一个......或者如果它们恰好相同(也就是说,你创建了一个图像,然后你碰巧创建了一个新的但相同的图像)你'会看到这个错误。

例如,以下代码在保存记录时可靠地重现了“无身份验证 token ”错误。它所做的只是创建一个 Assets 数组并将其放入记录中:

for (int i = 0; i <= maxPlayers; i++)
{
    int tempVal = 0xf;
    NSData *tempData = [[NSData alloc] initWithBytes:&tempVal length:sizeof(tempVal)];
    NSString *tempDataFilepath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"temp%d.dat",i]];
    [tempData writeToFile:tempDataFilepath atomically:YES];
    NSURL *tempDataURL = [NSURL fileURLWithPath:tempDataFilepath];
    someArray[i] = [[CKAsset alloc] initWithFileURL:tempDataURL ];
}

someRecord[SOME_FIELD_NAME] = someArray; 

只需将第三行更改为:

int tempVal = i; //force the temp value to be different every time

彻底解决错误。

此外,这个错误发生即使我试图在 不同 CKAsset **中使用一个值 **已经被使用在先前的 CKAsset 例如,在第一个 Assets 中使用 int tempVal = 0xf,然后在另一个 Assets 中使用 int secondTempVal = 0xf CKAsset 还会产生“无身份验证 token ”错误。

在我的案例中,我能够强制 Assets 值始终是唯一值,并彻底解决了问题。对于您的情况,我建议采用以下可能的解决方法:

  1. 检查您是否为 Assets 使用了相同的图像。如果是,请尝试为每个新 CKAsset 稍微修改图像。
  2. 如果您必须重复使用相同的图像,请尝试在设置每项 Assets 后保存记录。我不知道这是否能解决问题,而且它肯定会增加您的网络流量。但值得一试,看看它是否有帮助。
  3. 在这个问题中Saving CKAsset to CKRecord in CloudKit produces error: "No authToken received for asset" OP 能够创建最终解决问题的图像文件的单独副本。
  4. 打开 Apple 的错误。我没有费心去做这件事,因为我已经厌倦了看着类似的错误报告多年无人关注地打开。但谁知道呢,你的运气可能会更好。

关于ios - cloudkit 错误没有收到 Assets 的 authToken,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44983391/

有关ios - cloudkit 错误没有收到 Assets 的 authToken的更多相关文章

  1. ruby - i18n Assets 管理/翻译 UI - 2

    我正在使用i18n从头开始​​构建一个多语言网络应用程序,虽然我自己可以处理一大堆yml文件,但我说的语言(非常)有限,最终我想寻求外部帮助帮助。我想知道这里是否有人在使用UI插件/gem(与django上的django-rosetta不同)来处理多个翻译器,其中一些翻译器不愿意或无法处理存储库中的100多个文件,处理语言数据。谢谢&问候,安德拉斯(如果您已经在ruby​​onrails-talk上遇到了这个问题,我们深表歉意) 最佳答案 有一个rails3branchofthetolkgem在github上。您可以通过在Gemfi

  2. ruby-on-rails - Rails 常用字符串(用于通知和错误信息等) - 2

    大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje

  3. ruby - 难道Lua没有和Ruby的method_missing相媲美的东西吗? - 2

    我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/

  4. ruby-on-rails - rails 目前在重启后没有安装 - 2

    我有一个奇怪的问题:我在rvm上安装了ruby​​onrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(

  5. ruby - 在没有 sass 引擎的情况下使用 sass 颜色函数 - 2

    我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re

  6. ruby-on-rails - 迷你测试错误 : "NameError: uninitialized constant" - 2

    我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test

  7. ruby-on-rails - 如何在 Rails View 上显示错误消息? - 2

    我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c

  8. 使用 ACL 调用 upload_file 时出现 Ruby S3 "Access Denied"错误 - 2

    我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file

  9. ruby-on-rails - 错误 : Error installing pg: ERROR: Failed to build gem native extension - 2

    我克隆了一个rails仓库,我现在正尝试捆绑安装背景:OSXElCapitanruby2.2.3p173(2015-08-18修订版51636)[x86_64-darwin15]rails-v在您的Gemfile中列出的或native可用的任何gem源中找不到gem'pg(>=0)ruby​​'。运行bundleinstall以安装缺少的gem。bundleinstallFetchinggemmetadatafromhttps://rubygems.org/............Fetchingversionmetadatafromhttps://rubygems.org/...Fe

  10. ruby - #之间? Cooper 的 *Beginning Ruby* 中的错误或异常 - 2

    在Cooper的书BeginningRuby中,第166页有一个我无法重现的示例。classSongincludeComparableattr_accessor:lengthdef(other)@lengthother.lengthenddefinitialize(song_name,length)@song_name=song_name@length=lengthendenda=Song.new('Rockaroundtheclock',143)b=Song.new('BohemianRhapsody',544)c=Song.new('MinuteWaltz',60)a.betwee

随机推荐