昨天谷歌已经宣布了一套新的Firebase工具,其中之一就是Notifications能够从服务器向正在使用我的应用程序的设备发送通知.
但是,我们现在可以在收到新消息时通知用户吗?
如果没有,有没有办法实现这一目标?
push-notification firebase firebase-cloud-messaging firebase-notifications
我在我的应用程序中包含谷歌firebase - 创建谷歌帐户,创建谷歌应用程序,上传APNS认证(.pem和在另一项服务中工作),并从控制台发送推送通知,我的应用程序没有收到它.在Firebase控制台中,我看到状态已完成但设备的近似数量为" - "
当然,我更新了条款配置文件和APNS证书
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Register for remote notifications
if #available(iOS 8.0, *) {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
} else {
// Fallback
let types: UIRemoteNotificationType = [.Alert, .Badge, .Sound]
application.registerForRemoteNotificationTypes(types)
}
FIRApp.configure()
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.tokenRefreshNotificaiton),
name: kFIRInstanceIDTokenRefreshNotification, object: nil)
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
print(userInfo)
}
func tokenRefreshNotificaiton(notification: NSNotification) …Run Code Online (Sandbox Code Playgroud) apple-push-notifications ios firebase firebase-notifications
我喜欢下面的Swift 2.但它在Swift 3中不起作用.我怎么能提供这个?如果有人解释这将是伟大的.
didFinishLaunchingWithOptions
let notificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)
application.registerForRemoteNotifications()
Run Code Online (Sandbox Code Playgroud)
和
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
if notificationSettings.types != .None {
application.registerForRemoteNotifications()
}
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
print("Meesage ID \(userInfo["gcm_message_id"]!)")
print(userInfo)
}
Run Code Online (Sandbox Code Playgroud)
我可以做简单的本地通知,但是我无法从Firebase远程推送通知.
我试过了
UNUserNotificationCenter.currentNotificationCenter().delegate = self
UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions([.Alert, .Badge, .Sound]) { (success, error:NSError?) in
if success {
print("Notification access true!")
application.registerForRemoteNotifications()
}
else {
print(error?.localizedDescription)
}
}
Run Code Online (Sandbox Code Playgroud)
和
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { …Run Code Online (Sandbox Code Playgroud) 我正在创建一个应用程序,我希望能够设置基本通知(标题,消息,开火日期),并且一直试图找出设置通知的最佳方法.我正在使用Swift 3和Firebase 3.
我不想使用本地通知,因为如果用户登录多个设备,我希望它推送到所有这些设备.
有没有办法在FCM中执行此操作,用户可以在特定日期和时间设置触发通知并在登录的所有(iOS)设备上触发?
如果FCM没有这个,那还有另一个APK吗?我已经简要介绍了Batch,但我已经在使用Firebase了.
提前致谢!
firebase swift swift3 firebase-cloud-messaging firebase-notifications
如何在FirebaseMessagingService中合并推送通知.我几乎尝试了一切,但似乎没有任何工作.对于每个新的Data对象,它都会发出新的通知.我打印通知数量的日志打印0.
有没有任何方法我可以跟踪通知抽屉中是否有任何未读通知具有相同的notificationId,所以我可以将新的通知与它合并?
任何帮助将不胜感激.
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
private static final String actionLiked = "liked";
mNumber=0;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
ArrayList<String>notificationString= new ArrayList<>();
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
Log.d(TAG, "Number of notifications" +mNumber);
Map<String, String> dataFromCloud = remoteMessage.getData();
String action = dataFromCloud.get("action");
switch (action) {
case actionLiked:
notificationString.add(action); …Run Code Online (Sandbox Code Playgroud) android push-notification android-notifications firebase-cloud-messaging firebase-notifications
我被分配了一个使用Firebase来实现推送通知的任务,但我对此有点新意.
看文档:
https://firebase.google.com/docs/notifications/android/console-audience
Run Code Online (Sandbox Code Playgroud)
我不知道在什么情况下我应该使用send to user segment或send to a topic.
有人可以给我一些例子,何时使用其中一个并指出差异?谢谢你:)
push-notification firebase firebase-cloud-messaging firebase-notifications
我正在尝试将Firebase Messaging添加到我的iOS应用中。我遵循了Firebase文档中的步骤,即:
[FIRApp configure]@import FirebaseMessaging并添加了FIRMessagingDelegate但是,此时我得到一个错误:
@interface AppDelegate () <UNUserNotificationCenterDelegate, FIRMessagingDelegate>
// Cannot find protocol declaration for FIRMessagingDelegate
Run Code Online (Sandbox Code Playgroud)
我已经更新了我的Pod(由Stack Overflow上的类似问题建议),但仍然出现相同的错误。为了确认,运行pod update给出以下输出:
Using FirebaseMessaging (1.2.2)
Run Code Online (Sandbox Code Playgroud)
有什么建议么?
ios firebase firebase-cloud-messaging firebase-notifications
我已在我的应用中成功实施了Firebase消息传递.在后台工作得很好,当应用程序在前台时,会调用onMessageReceived()(yippee!).
我遇到的问题是我需要动态更新UI,而我仍然坚持实现这一目标的最佳方法.我不想向用户发送应用程序内通知(如示例代码所示),我不确定是否要发送广播,我想要做的就是访问MainActivity以调用方法已经存在,但我没有参考服务中的MainActivity.
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (remoteMessage.getNotification().getBody() != null) {
Log.d(LOG_TAG, "Message received: " + remoteMessage.getNotification().getBody());
} else {
Log.d(LOG_TAG, "Message received: " + remoteMessage.getData().get("message"));
}
// Call method in MainActivity
// <<< What goes Here?>>>>
}
Run Code Online (Sandbox Code Playgroud)
这似乎是一个简单的用例,但我无法在网上找到任何帮助.
提前致谢
我正在使用Firebase通知的应用程序.我在AppDelegate中配置了它,它们运行良好.
问题:我有一个带开关的设置视图,打开/关闭通知,我不知道如何禁用通知.我试过这个,但是没有用:
@IBAction func changeSwitch(_ sender: Any) {
if mySwitch.isOn {
print("NOTIFICATIONS ON")
connectToFcm()
} else {
print("NOTIFICATIONS OFF")
FIRMessaging.messaging().disconnect()
}
}
func connectToFcm() {
FIRMessaging.messaging().connect { (error) in
if (error != nil) {
print("Unable to connect with FCM. \(error)")
} else {
print("Connected to FCM.")
}
}
}
Run Code Online (Sandbox Code Playgroud)
也许你可以帮助我.
谢谢!
我想将通知发送到使用Node.Js代码中的Ionic t开发的Android应用程序。我尝试了以下代码并得到Exactly one of topic, token or condition is required.
如何无条件发送所有用户通知?
var serviceAccount = require("/path/to/config.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://myApp.firebaseio.com"
});
var message = {
notification: {
title: '$GOOG up 1.43% on the day',
body: '$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.'
}
};
admin.messaging().send(message).then(res=>{
console.log("Success",res)
}).catch(err=>{
console.log("Error:",err)
})
Run Code Online (Sandbox Code Playgroud) firebase firebase-authentication firebase-cloud-messaging firebase-notifications