From 3d98585fbe9e801e6cf402be41c5e7856a0e980b Mon Sep 17 00:00:00 2001 From: "Ali A. Hilal" Date: Tue, 14 Apr 2020 11:59:09 +0300 Subject: [PATCH] [Enhancement]: Deleting the temporary generated payload file after sending the push notification (#16) --- Sources/PoesCore/Send.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/PoesCore/Send.swift b/Sources/PoesCore/Send.swift index bfe8407..17cc861 100644 --- a/Sources/PoesCore/Send.swift +++ b/Sources/PoesCore/Send.swift @@ -41,11 +41,13 @@ struct Send: ParsableCommand, ShellInjectable { Log.debug("Generated payload:\n\n\(jsonString)\n") } - let url = Foundation.URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true).appendingPathComponent("payload.json") - FileManager.default.createFile(atPath: url.path, contents: jsonData, attributes: nil) + let tempUrl = NSTemporaryDirectory() + let payloadUrl = Foundation.URL(fileURLWithPath: tempUrl, isDirectory: true).appendingPathComponent("payload.json") + FileManager.default.createFile(atPath: payloadUrl.path, contents: jsonData, attributes: nil) Log.message("Sending push notification...") - Self.shell.execute(.push(bundleIdentifier: bundleIdentifier, payloadPath: url.path)) + Self.shell.execute(.push(bundleIdentifier: bundleIdentifier, payloadPath: payloadUrl.path)) Log.message("Push notification sent successfully") + try FileManager.default.removeItem(at: payloadUrl) } }