Group Group Group Group Group Group Group Group Group

Unregistered notification

When my app loads on the Ipad for the first time is fail to register with following com. If I update the app same results.

This happened after moving to Chapter 7 and adding the API calls.

I feel is it is Apple Certificate problem but not sure where to look in the webserver Vapor App or the IOS device app.

2021-06-09 00:56:01.591641-0400 PushNotifications[3838:1264594] [connection] nw_endpoint_handler_set_adaptive_read_handler [C1 10.0.0.218:8080 ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, ipv6, dns)] unregister notification for read_timeout failed

2021-06-09 00:56:01.591793-0400 PushNotifications[3838:1264594] [connection] nw_endpoint_handler_set_adaptive_write_handler [C1 10.0.0.218:8080 ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, ipv6, dns)] unregister notification for write_timeout failed

It get to the server on local ip each time I reload
INFO ] POST / [request-id: D9B1C208-5005-474F-82E9-C3B3E1C53E8B]

[ INFO ] POST / [request-id: 2DE28199-2B4A-4956-BFD2-5CA46D624D11]

[ INFO ] POST / [request-id: 0173C172-3359-41D1-989F-7013A1EF9EA8]

Those messages are just random noise that Xcode unfortunately spits out now. See this post https://developer.apple.com/forums/thread/681040

Yes I saw the one and only post on that noise issue.

This happened after moving to Chapter 7 and adding the API calls. The webserver will not save to data.

I know this is basic but I have coded ColdFusion for 25 years. And now I am trying to catch up with the real world.

I think I have missed something because in the push notification app I still have

var request = URLRequest(url: url)
request.addValue(“application/json”, forHTTPHeaderField: “Content-Type”)
request.httpMethod = “POST”
request.httpBody = details.encoded()

Json stuff shouldn’t that have been coded for the API?

How Can I force the Http Headers to show in the Output on the websever?

Are you referring to the sendPushNotificationDetails(to:using:) method in ApnsUploads.swift? What you’ve shown there is correct. You’re creating an outbound HTTP request (i.e. sending data to your web server) of type POST, and you’re telling the server that you are sending it JSON data via the Content-Type header (as opposed to XML, for example). The details.encoded() is just a helper method, from TokenDetails.swift that takes the struct and converts it to Data so that it can be transmitted.

Showing headers in the Vapor project…definitely, but honestly I haven’t touched Vapor in over a year now. You’ll probably get a much better/faster answer by posting to their Discord channel, which I referenced at the end of Chapter 6.

It’s 1am for me so I’m headed to bed, but I’ll check for any reply from you tomorrow. I think your best bet right now would be to run the Vapor project in the debugger, set a breakpoint in the route for the POST, and then step through to see what’s happening. Remember Vapor is ridiculously nested due to the completion handlers it has to use so you’ll want to set a breakpoint inside each completion handler as you can’t “step” into it.

I upload the Push App using the AppDelegate.swift and ApnsUploads.swift from chapter 7.

The AppDelegate call for the use of

didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
sendPushNotificationDetails(
to: “http://192.168.1.1:8080”,
using: deviceToken)
}

This will not save the token in the database.

If I add “http://192.168.1.1:8080/api/token”, This will not save the token in the database.
If I add “http://192.168.1.1:8080/token
When the app is launch the will you accept screens one and two launch and yes and yes will change the Notification settings. But it will not save to the token in the database. If I close app and bring it back to foreground it then saves the token.

It’s highly doubtful that 192.168.1.1 is your machine’s IP address. Please see Chapter 6, in the “Running your iOS app” section where I show how you find your mac’s IP address. that’s the IP you have to put in the call to sendPushNotificationDetails.

No you are correct my code looks like this

func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
sendPushNotificationDetails(
to: “http://10.0.0.218:8080/token”,
using: deviceToken)
}
}
I just used the code from the book as an example.
In the pushnotification app chapter 6 the app includes /Sources/App/Controller directories in which contain TokenController.swift. In Chapter 7 this directory is gone. what took the place of

func boot(router: Router) throws {
let routes = router.grouped(“api”, “token”)
routes.post(Token.self, use: storeToken)
routes.delete(String.parameter, use: removeToken)
}

Chapter 6 is focused on the server-side code, i.e. the Vapor project. That’s the only chapter where that code lives.

Chapter 7 moved back to the iOS project, which will contact the Vapor project via the http calls. You should still have the Vapor project running while you are working on the rest of the chapters.

Still working on the issue! Hopefully I will work through it.

Question how do you drop this into an IOS App is the a chapter that walks through that?

By “this” do you mean the Vapor part? You don’t. The Vapor part is your server-side code that will send push notifications to your customers.