Chapter 6/7- can't receive a notification

You shouldn’t be doing step 2. When you run the Vapor project it will create the tables appropriately. Please use Azure Data Studio to delete all tables that exist in the database and then rerun the vapor server so it creates them for you.

Did you manually insert the token or did you let the iOS app create it for you?

For step 7, did you enter the full path to the .p8 file? The pathname should start with a / character for it to work properly.

You’ve got sendPushes.php pointing at Apple’s development server, not the production server, right?

Your error means that it’s not properly connecting to your vapor server. It really seems like you’ve got something strange going on with your networking at your location, or the Vapor server isn’t configured with the proper IP address.

@gargoyle Oh ok. The way the pdf was written is confusing to me. It looks as if I needed to set up my own sql server that connects to docker db I created and create the table. Nowhere does it say that the vapor project will create it for you.

As far as the token goes I let the iOS app create it.

For step 7 I put the .p8 file in the same folder as the project, but did not put a slash in front of the file name. And yes sendPushes.php is pointing to Apples dev server.

@gargoyle just to confirm I just need to use Docker and vapor for this project along with xcode of course. Docker acts as my virtual server and vapor as my local server.

Docker is basically a virtual server, and it is what is running PostgreSQL for you. Most people don’t have a SQL server installed on their mac and so this is the easiest way to put one there.

Vapor is server side Swift (see our book dedicated to Vapor) and that is what runs your web server for you. It runs on your local machine directly. When the vapor server tries to open a connection to the SQL server, your machine redirects it to the PostgreSQL instance running inside of Docker.

I’ll try to explain all of this better in the next release of the book.

@gargoyle Ok I did all that you asked and everything is working. I am not longer getting any errors, but am still not receiving any notifications when I use sendPushes.php. Not sure what I am missing.

I did notice when I run the vapor server I dont get the second line in this statement. Could this be what is causing the problem?

[ INFO ] Migrating ‘psql’ database (FluentProvider.swift:28)

[ INFO ] Preparing migration ‘Token’ (MigrationContainer.swift:50)

[ INFO ] Migrations complete (FluentProvider.swift:32)

Running default command : /Users/scott/Library/Developer/Xcode/

DerivedData/dts-fdkxzqveujzmdycmruvnzrydjvwn/Build/Products/Debug/Run

serve

Server starting on http://192.168.1.1:8080

May someone tell me why static let entity = "tokens" is significant? I had the same problem as @clapslock. I’d just like to know why it resolved my problem of not receiving the notification. To me, it doesn’t look like entity is being used anywhere but I’m obviously wrong. Apparently it fixed something @gargoyle

@tunjifw Vapor looks for a static variable called entity. If it finds it, that is what it uses for the name of the table. If it doesn’t find it, then it creates a name based on the name of the class.

@jessemfulton The line you highlighted in bold is what Vapor will print out when it’s creating the database table if I remember right.

@gargoyle ok makes sense. Therefore the line below in the php script failed:
$sql = ‘SELECT DISTINCT token FROM tokens WHERE debug = :debug’;

Thanks for clearing that up. And @clapslock thanks for catching that bug.

@gargoyle So if its not printing this line out then it is not created the table correct? Any ideas as to why?

This is what I get in the output window.

[ INFO ] Migrating ‘psql’ database (/Users/jesse/Documents/Push_Notifications_by_Tutorials_v1.0/06-server-side-pushes/starter/.build/checkouts/fluent.git–9051137955613677038/Sources/Fluent/Migration/MigrationConfig.swift:69)

[ INFO ] Migrations complete (/Users/jesse/Documents/Push_Notifications_by_Tutorials_v1.0/06-server-side-pushes/starter/.build/checkouts/fluent.git–9051137955613677038/Sources/Fluent/Migration/MigrationConfig.swift:73)

Running default command: /Users/jesse/Library/Developer/Xcode/DerivedData/PushNotifications-awvdutjpuubbwraicqmffkymmrhp/Build/Products/Debug/Run serve

Server starting on http://192.168.0.1:8080

@jessemfulton Do you still have issues with this?

yes and the php script still fails as noted here.

@gargoyle I have followed everything in the book and added the Lin e
static let entity = “tokens”
to the PushNotifications vapor project in the Token class. I have looked in the docker container and the table tokens exists:
apns=# \c apns
You are now connected to database “apns” as user “apns”.
apns=# \d
List of relations
Schema | Name | Type | Owner
--------±-------±------±------
public | fluent | table | apns
public | tokens | table | apns

The rested app works and I still get the warning
Toms-MH-Mac:~ tom$ php /Users/tom/Repos/Push_Notifications_by_Tutorials_v1/07-expanding-the-application/starter/sendPushes.php

Warning: openssl_sign(): supplied key param cannot be coerced into a private key in /Users/tom/Repos/Push_Notifications_by_Tutorials_v1/07-expanding-the-application/starter/sendPushes.php on line 42

Warning: openssl_sign(): supplied key param cannot be coerced into a private key in /Users/tom/Repos/Push_Notifications_by_Tutorials_v1/07-expanding-the-application/starter/sendPushes.php on line 42

And no notification is recd.
@gargoyle can you help?

it might be helpful if you explained where you added the missing line: ( static let entity = "tokens" )

@tomtom At the top of your PHP script, can you check the AUTH_KEY_PATH to be sure it’s a full path, starting with /, to the p8 file you downloaded from Apple? Does the AUTH_KEY_ID contain the same value as the downloaded file had?

@tomtom Please see this forum post for information about the static let entity = "tokens" line.

Thanks. I was using ~/ instead of /Users/tom

@gargoyle
Thanks for your help. Now the toke works with the full path to the auth file. The the php script runs but no push and the Xcode console displays
2019-05-27 14:23:53.800165-0400 PushNotifications[7111:1505354] TIC TCP Conn Failed [2:0x282585e00]: 12:8 Err(-65554)

2019-05-27 14:23:53.801053-0400 PushNotifications[7111:1505351] Task <6E54D1F0-2D69-4D15-94CF-35310FD62F2C>.<1> HTTP load failed (error code: -1003 [12:8])

2019-05-27 14:23:53.801248-0400 PushNotifications[7111:1505351] Task <6E54D1F0-2D69-4D15-94CF-35310FD62F2C>.<1> finished with error - code: -1003

Error code 1003 is NSURLErrorCannotFindHost so it would appear that your box can’t talk to Apple for some reason.