首先,您需要在 Apple 开发者网站上注册并创建一个证书,这将使您能够使用 APNs。在 Apple 开发者网站上创建证书的过程相对简单,只需要按照网站上的说明进行操作即可。
2. 将证书添加到 Xcode 中
一旦您在 Apple 开发者网站上创建了证书,您需要将它添加到 Xcode 中。打开 Xcode,单击“File”>“New”>“Target”,然后选择“Notification Extension”或“Notification Service Extension”。在弹出的对话框中,选择“Certificate”,然后选择您在 Apple 开发者网站上创建的证书。
AndroidRuntime: FATAL EXCEPTION: main
AndroidRuntime: Process: com.xxx.app, PID: 25339
AndroidRuntime: java.lang.SecurityException: Not allowed to delete channel XXX with a foreground service
AndroidRuntime: at android.os.Parcel.createExceptionOrNull(Parcel.java:2376)
AndroidRuntime: at android.os.Parcel.createException(Parcel.java:2360)
AndroidRuntime: at android.os.Parcel.readException(Parcel.java:2343)
AndroidRuntime: at android.os.Parcel.readException(Parcel.java:2285)
AndroidRuntime: at android.app.INotificationManager$Stub$Proxy.deleteNotificationChannel(INotificationManager.java:4040)
AndroidRuntime: at android.app.NotificationManager.deleteNotificationChannel(NotificationManager.java:909)
AndroidRuntime: at androidx.core.app.NotificationManagerCompat.deleteNotificationChannel(SourceFile:2)
AndroidRuntime: at com.gyf.cactus.ext.c$a.run(SourceFile:1)
AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:938)
AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
AndroidRuntime: at android.os.Looper.loop(Looper.java:236)
AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:8142)
AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
AndroidRuntime: Caused by: android.os.RemoteException: Remote stack trace:
AndroidRuntime: at com.android.server.notification.NotificationManagerService$10.enforceDeletingChannelHasNoFgService(NotificationManagerService.java:3427)
AndroidRuntime: at com.android.server.notification.NotificationManagerService$10.deleteNotificationChannel(NotificationManagerService.java:3440)
AndroidRuntime: at android.app.INotificationManager$Stub.onTransact(INotificationManager.java:1737)
AndroidRuntime: at android.os.Binder.execTransactInternal(Binder.java:1160)
AndroidRuntime: at android.os.Binder.execTransact(Binder.java:1129)