通过推送通知服务添加图像?
我有一个内容应用程序,希望使用 Apple 推送通知服务向用户通知新内容,从而绕过现在很长的 App Store 提交。 用户收到通知后,下载更新按钮将启用。 用户将从我的网站下载一个 sql 文件和图像。 sql 文件将执行插入语句,图像将下载到磁盘。
我当前将内容(字符串和捆绑图像引用)加载到 UIWebView 中。 图像作为内容的一部分显示。 我将如何执行sql文件来插入新内容? 那么,我是否还需要开始引用磁盘上的图像而不是从捆绑包中引用图像,这是我在使用 App Store 更新提交时放置图像的位置?
对于 sql 文件,下载完成后我可能可以运行一些基于事件的代码。 但随后需要重新加载只读数据库才能看到新内容。 用户是否必须重新启动应用程序?
I have a content app and would like to notify users of new content using Apple Push Notification Service, bypassing the now very long App Store submissions. Once the user receives the notification, a download update button will become enabled. The user will download an sql file plus images from my website. The sql file will execute insert statements and the images will download to the disk.
I currently load content (strings and bundle image references) into a UIWebView. Images are displayed as part of the content. How would I execute the sql file to insert new content? Then, would I also need to start referencing images on disk rather than from the bundle, which is where I put images while using App Store update submissions?
For the sql file, I can probably run some event based code once the download is complete. But then the read only database needs to be reloaded for new content to be seen. Would the user have to restart the app?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如您所说,数据库对您的应用程序是只读的,我只需让 APN 触发新数据库文件的下载并将其写入磁盘,而不必执行 SQL 语句来修改现有数据库。 (除非您的数据库非常大并且您只进行了很小的更改,否则下载大小将是一个考虑因素)。
无论如何,如果您从捆绑包加载数据库,它将是只读的,因此您无法对其执行插入语句 - 您将需要制作一个可写的副本。 让更新过程完全替换此副本意味着您不必担心 SQL 在每个设备上正确执行。 例如,如果应用程序在插入过程中终止会发生什么?
同样,对于图像,如果在首次启动时将它们复制到可写图像目录而不是从捆绑包中加载,您的生活会更轻松,因此您始终在同一位置查找它们并且不关心是否有更新。 只需确保在更新后清理不再需要的所有内容,这样您就不会消耗比需要更多的用户存储空间。
As you said the database is read-only to your app, I would just have the APN trigger a download of a new database file and write it to disk instead of having to execute SQL statements to modify an existing db. (Unless your database is very large and you're only making a small change, when the download size would be a consideration).
In any case, if you are loading the database from the bundle it will be read-only so you can't execute insert statements on it - you will need to make a writable copy. Having the update process replace this copy in its entirety means you don't have to worry about the SQL executing correctly on each device. e.g. what happens if the app terminates mid-insert?
Similarly for images, your life would be easier if they were copied to a writable images directory on first launch rather than loaded from the bundle so you always look in the same place for them and don't care whether or not there's been an update. Just make sure you clean up anything that's no longer required after an update so you're not eating more of the user's storage than you need to.
当然,你可以这样做。
您在推送通知负载中添加一些自定义字段,就我而言,
'msgId' 可以是您需要的字段。
将负载发送到APN服务器(沙盒服务器/官方服务器,取决于您的情况)
将代码添加到接收APN
我在“updateDB”中使用了伪代码,并且使用了假URL,请将其替换为您的测试网址。 上面的操作有效,我做的很好。 但当我的应用程序处于后台时,我无法强制通知显示图像。
Of course, you can do so.
you add some custom field in your push notification payload, in my case,
the 'msgId' can the field you need.
send the payload to APN server (sandbox server/official server, depends on your situation)
add the code to receive APN
I used pseudo code in "updateDB", and fake URL, please replace it with your testing web URL. The above action works, I did it ok. But I cannot force the notification to show image when my app is in background.