我最近开始使用 Firebase Messaging,我希望其中一个客户端生成一个通知,该通知可以通过应用程序发送给其他用户,因此通过向服务器上游发送消息,然后从那里使用应用程序将其发送到其他设备似乎是一个解决方案
我在哪里可以在 firebase 控制台上看到我的 firebase 上游消息
public class FirebaseNotifier extends FirebaseMessagingService {
static FirebaseMessaging fmst;
static FirebaseInstanceId fid;
static Button b1;
public void onMessageReceived(RemoteMessage remoteMessage) {
sendNotification(remoteMessage);
}
private void sendNotification(RemoteMessage remoteMessage) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
int icon = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) ? R.drawable.myicon : R.drawable.myicon;
NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setSmallIcon(icon)
.setContentTitle(remoteMessage.getFrom())
.setContentText(remoteMessage.getNotification().getBody())
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过 firebase 向我的设备发送消息。但我得到了错误。我在高级 REST 客户端上成功测试了它。这是来自休息客户端的消息
Content-Type: application/json
Authorization: key=MY-KEY
Content-Length: 106
POST /fcm/send HTTP/1.1
HOST: fcm.googleapis.com
content-type: application/json
authorization: key=MY-KEY
content-length: 106
{
"to":"/topics/Self_Taught"
"notification":
{
"body":"Hello"
}
}
Run Code Online (Sandbox Code Playgroud)
基于此,我制作了我的 javascript 代码。不用担心gritter,它是其他库,并且可以正常工作。
$.ajax({
url: "https://fcm.googleapis.com/fcm/send",
type: "POST",
contentType: "application/json",
authorization: "key=MY-KEY",
data: {
"to": "/topics/Self_Taught",
"notification": {
"body": message
}
},
success: function (result) {
$.gritter.add({
title: "",
text: result.message_id,
class_name: 'gritter-success'
});
},
error: function (result) {
$.gritter.add({
title: "",
text: result.error,
class_name: 'gritter-error'
});
}
});
Run Code Online (Sandbox Code Playgroud)
这就是我从 result.error …
我只在一个设备中收到通知,该设备设置为存储在 mySQL DB 中的表的第一个令牌,并且通知不会发送到其余的令牌号。我尝试了一个WHILE循环并将令牌编号存储在一个数组中,但它不起作用。
请提出解决方案。谢谢你。
这是我的代码:

<?php
require "init.php";
$message=$_POST['message'];
$title=$_POST['title'];
$path_to_fcm='https://fcm.googleapis.com/fcm/send';
$server_key="A*************************Q";
$sql="select token from fcm_info";
$result =mysqli_query($con,$sql);
$row=mysqli_fetch_row($result);
$key=$row[0];
$headers = array(
'Authorization:key=' .$server_key,
'Content-Type:application/json'
);
$fields =array('to'=>$key,
'notification'=>array('title'=>$title,'body'=>$message));
$payload =json_encode($fields);
$curl_session =curl_init();
curl_setopt($curl_session,CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session,CURLOPT_POST, true);
curl_setopt($curl_session,CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl_session,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_session,CURLOPT_IPRESOLVE, CURLOPT_IPRESOLVE);
curl_setopt($curl_session,CURLOPT_POSTFIELDS, $payload);
$result=curl_exec($curl_session);
curl_close($curl_session);
mysqli_close($con);
?>
Run Code Online (Sandbox Code Playgroud) 我目前正在关注本网站的教程:http : //www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/
我可以从 firebase 控制台发送通知,但无法从 PHP 发送通知。
config_firebase.php
<?php
// Firebase API Key
define('FIREBASE_API_KEY', 'xxx');
?>
Run Code Online (Sandbox Code Playgroud)
push_firebase.php
<?php
class Push {
// push message title
private $title;
private $message;
private $image;
// push message payload
private $data;
// flag indicating whether to show the push
// notification or not
// this flag will be useful when perform some opertation
// in background when push is recevied
private $is_background;
function __construct() {
}
public function setTitle($title) {
$this->title = …Run Code Online (Sandbox Code Playgroud) 我想在不使用 Firebase 控制台的情况下发送通知(我想用服务器端制作)。为此,我正在尝试将设备令牌 ID 发送到 Web 服务。我在这个 Android 项目中使用 Firebase Cloud Messaging。我怎样才能做到这一点?
public class MyFirebaseInstanceIdService extends FirebaseInstanceIdService{
private static final String TAG = "MyFirebaseIIDService";
@Override
public void onTokenRefresh() {
String token = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Token: " + token);
sendRegistrationToServer(token);
}
private void sendRegistrationToServer(String token) {
// send token to web service ??
}
Run Code Online (Sandbox Code Playgroud)
谢谢 !
notifications android firebase server firebase-cloud-messaging
我在使用Swift的iOS应用中使用Firebase通知,最近我将Firebase Messaging从1.2.3更新为2,我的代码开始向右和向右突破.我解决了大部分问题,但我坚持这个问题.
这是我的部分AppDelegate应用程序功能导致我的问题:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.statusBarStyle = .lightContent
...
FirebaseApp.configure()
// [START add_token_refresh_observer]
// Add observer for InstanceID token refresh callback.
NotificationCenter.default.addObserver(self,
selector: #selector(self.tokenRefreshNotification),
name: .firInstanceIDTokenRefresh,
object: nil)
// [END add_token_refresh_observer]
return true
}
Run Code Online (Sandbox Code Playgroud)
当我尝试运行我的应用程序时,出现以下错误:
输入'NSNotification.Name?' 没有成员'firInstanceIDTokenRefresh'
已将firInstanceIDTokenRefresh重命名为其他内容吗?
我无法在Firebase Cloud Messaging控制台中上载APNs身份验证密钥。缺少“上传”按钮。
如果我的应用程序关闭,点击通知栏后,回调无法正常工作.
前景很好,但背景不好.
我用这个例子:https://ionicframework.com/docs/native/fcm/
我在Andoird上测试
谢谢
android firebase ionic-framework firebase-cloud-messaging angular
当用户未连接到xmpp时,我正在使用FCM通知进行聊天.
FCM中有2种通知模式1.通知消息2.数据消息
如果我的应用程序从最近清除,我将使用数据消息作为通知消息
这种方法适用于除Oreo之外的所有版本.
对于Oreo,如果应用程序未连接到xmpp和前台,我只会收到通知.我的onMessageReceived方法被调用了.
但是,当应用程序被杀死或仅从Oreo中删除时,同样的情况也不会发生.
编辑:我试过One Plus 3设备.
任何帮助表示赞赏.
我正在使用一些Swift和FCM代码,并且在更新了pod之后,我遇到了两个错误。我已经进行了研究,但无法弄清楚该如何解决。
这是代码:
// For iOS 10 display notification (sent via APNS)
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
// For iOS 10 data message (sent via FCM)
[FIRMessaging messaging].remoteMessageDelegate = self;
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeProd]; error message———> No visible @interface for 'FIRInstanceID' declares the selector 'setAPNSToken:type:'<--error message ends
NSLog(@"deviceToken1 = %@; %@",deviceToken,[[FIRInstanceID instanceID] token]);
}
Run Code Online (Sandbox Code Playgroud)
这是错误消息:
在类型为'FIRMessaging *'的对象上找不到属性'remoteMessageDelegate'
firebase ×10
android ×5
ios ×2
php ×2
swift ×2
ajax ×1
angular ×1
javascript ×1
objective-c ×1
server ×1