我正致力于通过FCM发送的天气应用程序的Rich Notification.
首先,我想通知您,我的通知是通过APNS和FCM成功发送和接收的.
CONTEXT
这是我发送的有效负载 Postman
{
"to": "/topics/03772",
"content_available": true,
"mutable_content": true,
"priority": "high",
"notification": {
"title": "Daily forecast",
"body": "Blue sky, no clouds",
"sound": "default",
"click_action": "weather"
},
"data": {
"timestamp": "1506103200",
"code": "03772",
"city": "London",
"attch": "7a",
"t": "15?",
}
}
Run Code Online (Sandbox Code Playgroud)
我喜欢这种Payload格式,我知道它有效,对我来说很清楚,也很容易理解.
解释:
用户可以通过将城市添加为收藏城市来订阅主题.主题是城市代码.
该data部分是从服务器发送的天气数据.
这是我的didReceive方法:
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) …Run Code Online (Sandbox Code Playgroud) firebase swift remote-notifications firebase-cloud-messaging
TL; DR:如果将视频存储在Assets.xcassets中,该如何播放视频?
我有大约50个要存储在应用程序中的视频。然后,我将使用按需资源获取来减轻我的应用大小。但是我只能通过将视频保存在Assets.xcassets中来实现此目的。而且我找不到从那里加载视频的方法,因为AVPlayer似乎只接受url,而且我不确定如何从本地存储资源中获取该信息。
更新:
因此,我做了进一步的挖掘,发现实际上不可能将视频存储在资产目录中并且仍然可以使用它们。我最终不得不将它们移出资产目录。至于按需资源获取,目录外的资源仍然有可能。您可以在此处找到类似的方法。
我想将 Assets.xcassets 中的图像附加到通知中。我一直在寻找解决方案大约一个小时,这似乎是唯一的方法:
func createLocalUrl(forImageNamed name: String) -> URL? {
let fileManager = FileManager.default
let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0]
let url = cacheDirectory.appendingPathComponent("\(name).png")
guard fileManager.fileExists(atPath: url.path) else {
guard
let image = UIImage(named: name),
let data = UIImagePNGRepresentation(image)
else { return nil }
fileManager.createFile(atPath: url.path, contents: data, attributes: nil)
return url
}
return url
}
Run Code Online (Sandbox Code Playgroud)
来源:我可以从 XCAssets 包中获取 NSURL 吗?
这似乎有点矫枉过正。但是,据我所知,这是获取可以使用的 URL 的唯一方法:
let imageURL = createLocalUrl(forImageNamed: "TestImage")
let attachment = try! UNNotificationAttachment(identifier: "image", url: imageURL!, options: …Run Code Online (Sandbox Code Playgroud) 我的图像资源目录有一个名为"自然"的文件夹,里面有数百个图像文件.
我想在我的图像资源中的"自然"目录下获得一组图像文件名.然后,我将从该数组中选择一个随机图像名称并显示它[UIImage imageNamed:@"..."].我被困在如何在'IncludedStudyImages'目录下获取一系列图像名称.我甚至无法在文档中找到有关如何以编程方式与我的图像资源交互的任何内容(除了显示它们).
谢谢你的帮助.
我正在使用 Kingfisher 库,但我的问题是我不能将它用于存储在资产中的图像 - 所有 Kingfisher 方法都需要 url,那么我如何将它用于资产?
ios ×4
swift ×4
assets ×1
avplayer ×1
firebase ×1
kingfisher ×1
objective-c ×1
swift4 ×1
video ×1