Group Group Group Group Group Group Group Group Group

Chapter 6/7- can't receive a notification

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

@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

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.