我需要在重新发送远程推送通知时从有效负载中捕获数据,在IOS 9上我使用func执行此操作:didReceiveRemoteNotification在IOS 10上使用swift 3.0我实现了这两个功能.
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
{
print("\(notification.request.content.userInfo)")
completionHandler([.alert, .badge, .sound])
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
{
print("User Info = ",response.notification.request.content.userInfo)
completionHandler()
}
Run Code Online (Sandbox Code Playgroud)
第二个功能仅在用户触摸推送时执行
当我的应用程序处于后台甚至关闭时,我需要在推送通知到达时捕获数据.
问候.问候
我从Azure函数开始。我有以下代码:
module.exports = function (context, req)
{
context.log('JavaScript HTTP trigger function processed a request.');
context.log(context.req.body.videoId)
if (context.req.body.videoId =! null)
{
context.log('inicia a obtener comentarios')
const fetchComments = require('youtube-comments-task')
fetchComments(req.body.videoId)
.fork(e => context.log('ERROR', e), p => {
context.log('comments', p.comments)
})
context.res = { body: fetchComments.comments }
}
else {
context.res = {
status: 400,
body: "Please pass a videoId on the query string or in the request body"
};
}
context.done();
};
Run Code Online (Sandbox Code Playgroud)
如何返回fetchComments返回的JSON?