// 使用Firebase Cloud Messaging SDK const admin = require('firebase-admin'); admin.initializeApp({ credential: admin.credential.applicationDefault() });
// 在每次用户登录并且Apple Wallet Pass准备注册时获取用户的推送令牌 router.post('/register', (req, res) => { const pushToken = req.body.pushToken;
// 将push令牌写入到用户的数据库记录中 // ...
// 将push令牌传输到客户端 const payload = { aps: { alert: 'You have a new pass!' }, pushToken: pushToken }; admin.messaging().sendToDevice(deviceToken, payload) .then(response => { console.log(response); }) .catch(error => { console.error(error); }); });
PKAddPassesViewController *addController = [[PKAddPassesViewController alloc] initWithPass:pass]; addController.delegate = self;
// 检查是否有推送令牌,如有则添加到请求中 if (pushToken) { addController.userInfo = @{@"pushToken": pushToken}; }
[self presentViewController:addController animated:YES completion:nil];
addPassesViewController:didFinishAddingPasses:方法来实现。
示例代码: