I'm currently working on iOS push notifications using Laravel as backend.
I was able to send a notification to iOS apps ,however, the text originally written in Japanese was garbled.
・laravel 5.7
app/Console/Commands/SendPushNotification.php
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Notifications\PushNotification;
use App\User;
class SendApnsNotLogin extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'push:apns';
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'send notification';
    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }
    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //get the people who receive notifications 
        $users = User::all();
        foreach($users as $user) {
            $user->notify(new PushNotification);
        }
    }
}
app/Notifications/PushNotification.php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use NotificationChannels\Apn\ApnChannel;
use NotificationChannels\Apn\ApnMessage;
mb_language("Japanese");
mb_internal_encoding("UTF-8");
********omitted*******
public function via($notifiable)
    {
        return [ApnChannel::class];
    }
    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toApn($notifiable)
    {
        return ApnMessage::create()
                    ->badge(1)
                    ->title("タイトル部分")
                    ->body("ボディ部分");
    }
    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
I would appreciate it if somebody gave me tips on how to avoid text garbling and how to send Japanese push notifications.
via Chebli Mohamed
 
Aucun commentaire:
Enregistrer un commentaire