function sendPushNotification($user_id, $title, $body, $data = []) { global $pdo; // Get user's device token $stmt = $pdo->prepare("SELECT device_token FROM device_tokens WHERE user_id = ?"); $stmt->execute([$user_id]); $device_token = $stmt->fetchColumn(); if (!$device_token) { return false; } $notification = [ 'aps' => [ 'alert' => [ 'title' => $title, 'body' => $body ], 'sound' => 'default' ] ]; // Add custom data if (!empty($data)) { $notification['data'] = $data; } // Your APNs configuration $apns_key = 'ios_app/AuthKey_GU2P6JS8K6.p8'; $key_id = 'GU2P6JS8K6'; $team_id = '78SS82JP67'; $bundle_id = 'sss.SlipShareV5'; // Send to APNs $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.push.apple.com/3/device/$device_token"); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($notification)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Authorization: bearer " . generateJWT($team_id, $key_id, $apns_key), "apns-topic: $bundle_id", "apns-push-type: alert" ]); $response = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $http_code == 200; }