- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
为什么当我在 iOS 设备上构建应用程序时会显示该消息,但当将应用程序推送到 Apple Store 时却没有收到通知。
我已经启用了推送通知功能 enter image description here
这是 Appdelegate 文件的所有代码
访问https://ideone.com/ErsdDS查看代码
import UIKit
import Firebase
import FirebaseInstanceID
import FirebaseMessaging
import UserNotifications
import GoogleMaps
import GooglePlaces
import CoreData
//import MessagingDelegate
@available(iOS 10.0, *)
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate,MessagingDelegate {
static var mangedObjectContext: NSManagedObjectContext?
var window: UIWindow?
let gcmMessageIDKey = "gcm.message_id"
let key = "AIzaSyDzuGKTfmkbR_VBffp....11Gz7pFOX2c"
//
// func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
//
//
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
///
FirebaseApp.configure()
GMSServices.provideAPIKey("AIzaSyD2kiw....qFi-z2-iEzdcbvloSNOweBo")
GMSPlacesClient.provideAPIKey("AIzaSyD2ki....1qFi-z2-iEzdcbvloSNOweBo")
// [START set_messaging_delegate]
Messaging.messaging().delegate = self
// [END set_messaging_delegate]
// Register for remote notifications. This shows a permission dialog on first run, to
// show the dialog at a more appropriate time move this registration accordingly.
// [START register_for_notifications]
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
//
AppDelegate.mangedObjectContext = persistentContainer.viewContext
return true
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
print(userInfo)
}
func applicationDidFinishLaunching(_ application: UIApplication) {
FirebaseApp.configure()
GMSServices.provideAPIKey("AIzaSyD2kiwgq9e1qFi-z2-iEzdcbvloSNOweBo")
// [START set_messaging_delegate]
Messaging.messaging().delegate = self
// [END set_messaging_delegate]
// Register for remote notifications. This shows a permission dialog on first run, to
// show the dialog at a more appropriate time move this registration accordingly.
// [START register_for_notifications]
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
print(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Unable to register for remote notifications: \(error.localizedDescription)")
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
print("APNs token retrieved: \(deviceToken)")
}
func application(application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
Messaging.messaging().apnsToken = deviceToken as Data
}
func applicationWillResignActive(_ application: UIApplication) {
}
func applicationDidEnterBackground(_ application: UIApplication) {
}
func applicationWillEnterForeground(_ application: UIApplication) {
}
func applicationDidBecomeActive(_ application: UIApplication) {
}
func applicationWillTerminate(_ application: UIApplication) {
}
lazy var persistentContainer: NSPersistentContainer = {
/*
The persistent container for the application. This implementation
creates and returns a container, having loaded the store for the
application to it. This property is optional since there are legitimate
error conditions that could cause the creation of the store to fail.
*/
let container = NSPersistentContainer(name: "Model")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
/*
Typical reasons for an error here include:
* The parent directory does not exist, cannot be created, or disallows writing.
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space.
* The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was.
*/
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()
// MARK: - Core Data Saving support
func saveContext () {
let context = persistentContainer.viewContext
if context.hasChanges {
do {
try context.save()
} catch {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
}
}
@available(iOS 10, *)
extension AppDelegate : UNUserNotificationCenterDelegate {
// Receive displayed notifications for iOS 10 devices.
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
// With swizzling disabled you must let Messaging know about the message, for Analytics
// Messaging.messaging().appDidReceiveMessage(userInfo)
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
// Print full message.
print(userInfo)
// Change this to your preferred presentation option
completionHandler([.alert,.sound])
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
// Print full message.
print(userInfo)
completionHandler()
}
}
@available(iOS 10.0, *)
extension AppDelegate {
// [START refresh_token]
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
print("Firebase registration token: \(fcmToken)")
InstanceID.instanceID().instanceID { (result, error) in
if let error = error {
print("Error fetching remote instange ID: \(error)")
} else if let result = result {
print("Remote instance ID token: \(result.token)")
tokenfb = result.token
print("tao dang tesst: \(tokenfb)")
}
saveCache(key: "tokenfb", value: tokenfb)
// TODO: If necessary send token to application server.
// Note: This callback is fired at each app startup and whenever a new token is generated.
}
}
// [END refresh_token]
// [START ios_10_data_message]
// Receive data messages on iOS 10+ directly from FCM (bypassing APNs) when the app is in the foreground.
// To enable direct data messages, you can set Messaging.messaging().shouldEstablishDirectChannel to true.
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
print("Received data message: \(remoteMessage.appData)")
}
// [END ios_10_data_message]
}
*请帮助我!
最佳答案
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)
{
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Sandbox)
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Prod)
}
FIRInstanceIDAPNSTokenType.Sandbox used when we download it from TestFlight or when we are testing in development mode and FIRInstanceIDAPNSTokenType.Prod used when we release production build or when we download from AppStore
关于ios - 无法在 iOS 设备上从 Apple Store 接收通知(fcm),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51923938/
我正在尝试使用 Firebase 云消息传递。我将通知从 Node.js 服务器发送到我注册到通知系统的应用程序。 我的问题是,在 Android 5.1 上,即使我在 nofitification
根据FCM documentation如果 FCM 服务器检测到高优先级消息不会导致用户交互的模式,则高优先级消息可能会被取消优先级。该机制的细节未指定。问题: 这究竟是如何工作的? 检测算法如何收集
更新到最新的 Firebase 后,无法获取所选 的 FCM 注册 token fcmSenderId : FirebaseInstanceId .getInstance()
我想在单个 fcm 请求中向多个设备发送通知。我的通知文本对于所有设备都是相同的。我必须同时向所有用户发送超过 10000 条通知,并且文本是相同的,所以我想以最小的 fcm 请求发送所有通知。我正在
// body 就像这样 { "to": "/topics/NEWS" , "data":{ "extra_information": "This is
当我在浏览器中生成 FCM token 时,我还将其发送到我的服务器,服务器使用 firebase 管理模块将其订阅到主题,如下所示: messaging.subscribeToTopic(token
我正在开发一个应用程序,我想通过 php 实现 FCM 推送通知。 所以我制作了两个java文件:1.FirebaseInstanceID(工作正常并在数据库中正确获取 token )2.Fireba
我正在尝试使用 cordova-plugin-firebasex 向我的cordova 应用程序上的特定用户发送通知这是 cordova-plugin-firebase 的一个 fork 修复和改进。
我正在尝试使用以下方法从我的 iOS-Objective-C 应用发送消息: NSInteger iTime = [NSDate timeIntervalSinceReferenceDate]
我正在尝试为 FCM 实现服务器以向 android/iOS 设备发送通知。 我需要向 android 和 iOS 发送纯数据通知,但 iOS 的后台通知似乎非常不稳定。 (即使该应用程序在前台,我也
我对向手机发送通知的选项感到困惑。我在 Azure 上部署了在 .Net core 中创建的后端。现在,当管理员推出新优惠时,必须将推送通知发送到移动设备。我找到了 3 个很好的替代品。所有人都以自己
我用 POST 设置了一个 REST 客户端 --> https://fcm.googleapis.com/fcm/send 内容类型:应用程序/json 授权: key = JSON 正文: {
我在 Flutter 应用程序中使用 firebase_messaging v9.0.1。关于基于 https://pub.dev/packages/firebase_messaging/exampl
当我使用 Firebase 控制台时,通过激活“高级选项”下的“声音”一切都是完美的,正如 Mouad Abdelghafour AitAli 在接受的答案中所解释的那样 Firebase Push
我已经尝试在 Curl 中使用以下命令使用 Firebase REST Api 发送通知并且它有效: curl -X POST --header "Authorization: key=AIza...
即使 ios 也可以从 fcm 控制台获得通知。 Controller 功能 : public function push(Request $request) { $validator = V
对于通过 XMMP 支持上行和下行消息的服务器端实现,我使用 org.jivesoftware.smack.tcp.XMPPTCPConnection。我从 GCM 迁移到 FCM,现在我的应用服务器
这是我的代码: function sendToken(token) { $.ajax({ url: 'https://iid.googleapis.com/iid/v1/' + token
这是我第一次使用 Flutter 测试 FCM。我检查了一些来自 GitHub 的 SO 问题和文档。 我能够发送通知,当应用程序未运行时它们会被发送。 如果应用程序正在运行或在后台,则消息不可见。
我正在尝试在未接收但他们在调试 apk 中发送/接收很好的发布应用程序中发送 FCM 通知(在用户之间发送消息、好友请求等),我有对此进行了搜索,发现一些对我不起作用的解决方案 像这样,我把它放在 p
我是一名优秀的程序员,十分优秀!