对于Swift3 / iOS10,请参见以下链接:
ios10,Swift3和Firebase推送通知(FCM)
我正在尝试使用Firebase进行通知,并且完全按照文档中的说明进行了集成。但是我不明白为什么它不起作用。在构建项目时,我看到以下行:
2016-05-25 16:09:34.987: <FIRInstanceID/WARNING> Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"
这是我的AppDelegate:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
FIRApp.configure()
FIRDatabase.database().persistenceEnabled = true
var service: DataService = DataService()
service.start()
registerForPushNotifications(application)
application.registerForRemoteNotifications()
return true
}
func registerForPushNotifications(application: UIApplication) {
let notificationSettings = UIUserNotificationSettings(
forTypes: [.Badge, .Sound, .Alert], categories: nil)
application.registerUserNotificationSettings(notificationSettings)
}
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
if notificationSettings.types != .None {
application.registerForRemoteNotifications()
}
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let tokenChars = UnsafePointer<CChar>(deviceToken.bytes)
var tokenString = ""
for i in 0..<deviceToken.length {
tokenString += String(format: "%02.2hhx", arguments: [tokenChars[i]])
}
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Unknown)
print("Device Token:", tokenString)
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
// Print message ID.
print("Message ID: \(userInfo["gcm.message_id"]!)")
// Print full message.
print("%@", userInfo)
}
1.在 didFinishLaunchingWithOptions 方法中设置Notification Observer
2. 然后设置 tokenRefreshNotification 方法,然后在此方法中获取令牌。
见下面的代码
import Firebase
import FirebaseMessaging
override func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
FIRApp.configure()
NotificationCenter.default.addObserver(self,
selector: #selector(self.tokenRefreshNotification(notification:)),
name: NSNotification.Name.firInstanceIDTokenRefresh,
object: nil)
}
// NOTE: Need to use this when swizzling is disabled
public func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Sandbox)
}
func tokenRefreshNotification(notification: NSNotification) {
// NOTE: It can be nil here
let refreshedToken = FIRInstanceID.instanceID().token()
print("InstanceID token: \(refreshedToken)")
connectToFcm()
}
func connectToFcm() {
FIRMessaging.messaging().connectWithCompletion { (error) in
if (error != nil) {
print("Unable to connect with FCM. \(error)")
} else {
print("Connected to FCM.")
}
}
}
public func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
print(userInfo)
}
我正在处理react native Expo的推送通知。我刚刚开始,无法获得世博推送通知令牌。我添加了以下代码: 并收到错误“[未处理的承诺拒绝:错误:Expo push notification service仅支持Expo项目。请确保您已登录到正在加载项目的计算机上的Expo developer帐户。]”。 我正在Expo应用程序中运行该项目,我已经在Expo上创建了一个帐户,但仍然没有得到令
我正在开发一个倒计时应用程序,目前正在尝试在倒计时运行时退出应用程序时显示通知。相应地,我希望在用户返回应用程序时通知消失。 到目前为止,我已经设法使它适用于带有静态文本的简单通知,执行以下操作:在MainActivity.java中,在onStop()中,我创建一个意图并使用start Service(意图)启动服务。对称地,在onStart()中,我运行stop Service(意图),以便当
请求header GET /v1/notify Authorization:Bearer {ACCESS TOKEN} Content-Type:application/json 注:请将上方的{ACCESS TOKEN}替换为您的ACCESS TOKEN 返回 { "result": "success", "url": "http://www.foo.com/" }
我试图使用从Spring应用程序中的公共客户端获取访问令牌。 谁能帮我弄清楚我做错了什么吗?
所以,昨天一切都很好,但现在Android Studio和我的项目抛出了这个错误: 我谷歌了很长时间,但还没有找到任何解决方案。我的项目没有任何单词“Assemble”(项目中的Ctrl+Shift+F)。 gradlew clean Build-StackTrace:
我用JHipster 5.1.0生成了一个UAA服务器。我选择PostgreSQL作为数据库类型。 它连接到我的jhipster注册表,然后我生成了一个微服务和一个网关,如下所示: 启动网关进行用户登录后,它无法获取访问令牌并引发错误: 2018-07-23 17:32:53.378调试7228---[XNIO-2 task-10]c.c.c.a.g.a.AccessControlFilter:访