我正在完成本教程(https://www.youtube.com/watch?v=JsWHzU1DxjM),尝试将推送通知放入我的iOS应用程序.我能够成功获得APNS的证书,并将"推送通知"和"后台模式"功能设置为开启.此外,当我从firebase控制台发送一个通知时,Firebase可以从通知中获取信息.但是,当应用程序在后台运行时,横幅通知永远不会出现.我觉得我可能在将教程从Objective-C转换为Swift时遇到了问题,因为该教程是在Objective-C中,但我不确定.我把我的AppDelegate类和程序输出如果有帮助的话.
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
connectToFcm()
NSNotificationCenter.defaultCenter().addObserver(
self,
selector: #selector(tokenRefreshCallback),
name: kFIRInstanceIDTokenRefreshNotification,
object: nil)
let allNotificationTypes = UIUserNotificationType(arrayLiteral: UIUserNotificationType.Sound, UIUserNotificationType.Alert, UIUserNotificationType.Badge)
let settings = UIUserNotificationSettings(forTypes: allNotificationTypes, categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
override init() {
FIRApp.configure()
FIRDatabase.database().persistenceEnabled = …Run Code Online (Sandbox Code Playgroud) 我在Android应用程序中实现了Firebase通知.当我的应用程序运行时,将显示包含我的自定义布局的通知,但是当应用程序未运行时,通知将以默认布局显示.如何在应用程序未运行时将通知布局更改为我的布局.此外,我存储共享首选项以允许用户切换通知.但是当应用程序未运行时,无论如何都会显示通知.怎么能实现呢?
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if(SettingsFragment.getReceiceNotification()){ //if user wants to receive notification
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
RemoteViews remoteViews = new RemoteViews(getPackageName(),R.layout.push_notification_layout);
remoteViews.setImageViewResource(R.id.push_notif_icon,R.mipmap.ic_bird_black);
Intent intent = new Intent(this,MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setContent(remoteViews);
notificationBuilder.setContentTitle("Radyo Türkku?u");
notificationBuilder.setContentText(remoteMessage.getNotification().getBody());
notificationBuilder.setAutoCancel(true);
notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
notificationBuilder.setContentIntent(pendingIntent);
remoteViews.setTextViewText(R.id.push_title, "Radyo Türkku?u");
remoteViews.setTextViewText(R.id.push_context, remoteMessage.getNotification().getBody());
//notificationBuilder.setLights (ContextCompat.getColor(MainActivity.context, R.color.pushColor), 5000, 5000);
notificationManager.notify(0,notificationBuilder.build());
}
}
Run Code Online (Sandbox Code Playgroud) android firebase firebase-cloud-messaging firebase-notifications
我正在尝试使用FCM进行通知.
但<FIRInstanceID/WARNING>无法获取APNS令牌错误Domain=com.firebase.iid Code=1001 "(null)"发生,所以我无法得到通知.有什么问题?
在控制台,
无法获取APNS令牌Error Domain=com.firebase.iid Code=1001 "(null)"
以下是我的代码 Appdelegate
import UIKit
import CoreData
import Alamofire
import Firebase
import FirebaseInstanceID
import FirebaseMessaging
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var badgeCount : Int = 0;
enum BasicValidity : String {
case Success = "basicInfo"
case Fail = "OauthAuthentificationError"
}
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let …Run Code Online (Sandbox Code Playgroud) ios firebase swift firebase-cloud-messaging firebase-notifications
我正在尝试处理启动选项并在点击我在swift 3中收到的远程通知时打开一个特定的视图控制器.我已经看到类似的问题,例如这里,但没有新的swift 3实现.我看到了一个类似的问题(和)在AppDelegate.swift中我在didFinishLaunchingWithOptions中有以下内容:
var localNotif = (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] as! String)
if localNotif {
var itemName = (localNotif.userInfo!["aps"] as! String)
print("Custom: \(itemName)")
}
else {
print("//////////////////////////")
}
Run Code Online (Sandbox Code Playgroud)
但是Xcode给了我这个错误:
Type '[NSObject: AnyObject]?' has no subscript members
Run Code Online (Sandbox Code Playgroud)
我也试过这个:
if let launchOptions = launchOptions {
var notificationPayload: NSDictionary = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] as NSDictionary!
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
error: ambiguous reference to member 'subscript'
Run Code Online (Sandbox Code Playgroud)
我有类似的错误,无论我以前使用类似的代码通过键从字典中获取值,我不得不替换代码,基本上安全地首先解开字典.但这似乎不适用于此.任何帮助,将不胜感激.谢谢.
ios firebase swift firebase-cloud-messaging firebase-notifications
我在App上工作,我需要在其中显示通知.对于通知,我正在使用FireBase云消息传递(FCM).当app在后台时,我能够获得通知.
但是当我点击通知时,它会重定向到home.java页面.我希望它重定向到Notification.java页面.
所以,请告诉我如何在点击通知中指定活动.我使用两种服务:
1.)MyFirebaseMessagingService
2.)MyFirebaseInstanceIDService
这是我在MyFirebaseMessagingService类中的onMessageReceived()方法的代码示例.
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "FirebaseMessageService";
Bitmap bitmap;
public void onMessageReceived(RemoteMessage remoteMessage) {
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());
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " …Run Code Online (Sandbox Code Playgroud) android android-notifications firebase-cloud-messaging firebase-notifications
import Firebase
import FirebaseInstanceID
import FirebaseMessaging
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
registerForPushNotifications(application)
FIRApp.configure()
// Add observer for InstanceID token refresh callback.
NSNotificationCenter
.defaultCenter()
.addObserver(self, selector: #selector(AppDelegate.tokenRefreshNotificaiton),
name: kFIRInstanceIDTokenRefreshNotification, object: nil)
// Override point for customization after application launch.
return true
}
func registerForPushNotifications(application: UIApplication) {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
print("===== didReceiveRemoteNotification ===== …Run Code Online (Sandbox Code Playgroud) ios firebase google-cloud-messaging firebase-cloud-messaging firebase-notifications
我正在考虑在数据库中保留所有注册ID(推送令牌)并从iPhone发送通知给用户.我试过这样的事情,但没有得到任何通知.
func sendPNMessage() {
FIRMessaging.messaging().sendMessage(
["body": "hey"],
to: TOKEN_ID,
withMessageID: "1",
timeToLive: 108)
}
Run Code Online (Sandbox Code Playgroud)
我做错了什么或者根本不可能做到这一点?
ios firebase google-cloud-messaging firebase-cloud-messaging firebase-notifications
Heloo,我正在构建一个应用程序,我通过Firebase控制台使用推送通知.我想知道简单推送通知和云消息之间的区别是什么?来自云消息传递的消息是数据消息(具有密钥和值),通知只是没有密钥和值的文本吗?我是对的吗?
google-cloud-messaging firebase-cloud-messaging firebase-notifications
我想为我的Android应用程序使用Firebase通知,我想知道的是主题数量有任何限制吗?或者可以订阅主题的用户数量?例如,我可以拥有10000个主题,每个主题有100万用户吗?
我是FCM的新手.我无法让FCM使用我的应用程序图标作为通知图标,图标始终为白色空白图标.
我向mipmap文件夹导入了一个图标但似乎没有任何改变.正如一些家伙所说,这是因为在这个问题中的棒棒糖通知
但问题是,FCM通知会自动弹出,我无法让Notification构建器覆盖图标.我该怎么改变它?
android android-notifications firebase firebase-cloud-messaging firebase-notifications