Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
199 views
in Technique[技术] by (71.8m points)

ios - How to send apns token to server with additional data

I am trying to send an apns token to my server when didRegisterForRemoteNotificationsWithDeviceToken is called. I can successfully print the token to the console, so I know that part is working.

I have also implemented such an endpoint on my web service, which is also working just fine with the rest of my app.

In the Apple Developer documentation, under the last section called Forward Tokens to Your Provider Server it says

Upon receiving a device token, open a network connection from your app to your provider server. Securely forward the device token and any other information you need to identify the specific user to your server. For example, you might include the user's login name or something that connects them to your service.

Practically speaking, how do I include information like this? I can't seem to pass additional parameters into didRegisterForRemoteNotificationsWithDeviceToken, like a user's access token, userid, etc.

Since I'm using SwiftUI, the all the user's info, including their access token, is in an @EnvironmentObject in my view structs. Do I need to switch to a singleton or something?

question from:https://stackoverflow.com/questions/65860400/how-to-send-apns-token-to-server-with-additional-data

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could encode the struct that holds all the user metadata, including the token, into a JSON JSONEncoder and send it in a request to the server.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...