【问题标题】:Error __NSCFLocalDownloadFile error 2 creating temp错误 __NSCFLocalDownloadFile 错误 2 创建临时文件
【发布时间】:2017-07-22 06:59:51
【问题描述】:
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];

@synchronized (session)
{
    [[session downloadTaskWithURL:attachmentURL
                completionHandler:^(NSURL *temporaryFileLocation, NSURLResponse *response, NSError *error) {
                    if (error != nil) {
                        NSLog(@"error.localizedDescription %@", error.localizedDescription);
                    } else {
                        NSFileManager *fileManager = [NSFileManager defaultManager];
                        NSURL *localURL = [NSURL fileURLWithPath:[temporaryFileLocation.path stringByAppendingString:fileExt]];
                        [fileManager moveItemAtURL:temporaryFileLocation toURL:localURL error:&error];

                        NSError *attachmentError = nil;
                        attachment = [UNNotificationAttachment attachmentWithIdentifier:@"" URL:localURL options:nil error:&attachmentError];
                        if (attachmentError) {
                            NSLog(@"attachmentError.localizedDescription %@", attachmentError.localizedDescription);
                        }
                    }
                    completionHandler(attachment);
                }] resume];
}

我正在使用 FCM 进行推送通知。

{
"to": "ffHjl2CblrI...",
"data": {
    "message": "Offer!",
    "image": "https://media.giphy.com/media/l4lR0Q5u91kTNJPsA/giphy.gif",
    "url": custom url,
    "mediaType": "gif",
    "type": "notification type"
},
"notification": {
    "body": "Body",
    "sound": "default",
    "title": "Title"
},
"content_available": true,
"mutable_content": true
}

这是我的有效载荷内容。

我正在使用 NotificationExtension 上面的代码,用于从推送通知中下载数据。

我收到了来自开发者证书的成功响应。如果我检查生产证书(更新以前的证书),我会收到这样的错误

__NSCFLocalDownloadFile: error 2 creating temp file: /private/var/mobile/Containers/Data/PluginKitPlugin/7D6B57B4-DC4D-4F3E-8113-C8469BA66BBB/tmp/CFNetworkDownload_NQQfGi.tmp

如果我删除该应用程序并再次运行,它就可以工作。但是如果我用新的 IPA 更新版本,它不会在通知中显示图像。

我想念的是证书问题吗?是应用权限问题吗?

我正在为UNNotificationServiceExtension 使用单独的 APP ID(没有推送通知配置)。

更新

还检查了 APNS 是否也无法正常工作。

关于 APNS 和有效负载内容的更多代码和解释

  1. Richmedia notification notification not working in production certifcate

  2. Rich push notification not work properlly after update IPA (same IPA with overwirtten)

【问题讨论】:

    标签: ios firebase nsurlsession nsurlsessiondownloadtask unnotificationattachment


    【解决方案1】:

    我遇到了这个错误,它属于 PESIXErrorDomain,我很确定这是 iOS 10 中可能与 other bugs 一起引入的一个 iOS 错误。

    我实施的解决方法是使当前会话无效,启动一个新会话并使用获取的恢复数据的新会话启动一个新的下载任务。

    【讨论】:

    • 但是,这适用于开发证书和应用商店证书(使用 testflight)。
    • 我不知道它是否仅限于测试版本
    猜你喜欢
    • 2015-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多