开发者社区> 问答> 正文

向带有Laravel后端的iOS应用程序发送推送通知时,如何避免文本乱码?

我目前正在使用Laravel作为后端编写iOS推送通知。

我向iOS应用程序发送了一份通知,但是原来用日语写的文字被弄错了。

·Laravel 5.7

app/控制台/命令/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/Notificationphp/PushNotificationphp

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 [
            //
        ];
    }

如果有人给我一些如何避免文字混乱和如何发送日文推送通知的建议,我将不胜感激。

展开
收起
游客5akardh5cojhg 2019-12-24 13:18:06 1264 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载