- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试将 Firebase 通知添加到我的应用中。我的应用程序甚至在启动之前就出现了错误。另外,从我的应用程序调用通知与从 Firebase 调用通知有什么区别?是否无法从我的应用程序调用通知,这就是为什么需要 firebase 通知?我对通知一无所知,简单的总结会很棒。谢谢
import UIKit
import Firebase
import GoogleSignIn
import FBSDKCoreKit
import TwitterKit
import IQKeyboardManagerSwift
import OAuthSwift
import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
var window: UIWindow?
static var shared: AppDelegate { return UIApplication.shared.delegate as! AppDelegate }
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
GIDSignIn.sharedInstance().delegate = self
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
IQKeyboardManager.sharedManager().enable = true
Twitter.sharedInstance().start(withConsumerKey: "6nQtUKZChHOJ0iNjUsHuJoMrH", consumerSecret: "CEEfZPMx4BSNel4eknivDCHALrWpxR5NBpjgtxmYxzFipTPJcz")
FirebaseApp.configure()
application.registerForRemoteNotifications()
requestNotificationAuthorization(application: application)
if let userInfo = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] {
NSLog("[RemoteNotification] applicationState: \(applicationStateString) didFinishLaunchingWithOptions for iOS9: \(userInfo)")
//TODO: Handle background notification
}
return true
}
var applicationStateString: String {
if UIApplication.shared.applicationState == .active {
return "active"
} else if UIApplication.shared.applicationState == .background {
return "background"
}else {
return "inactive"
}
}
func requestNotificationAuthorization(application: UIApplication) {
if #available(iOS 10.0, *) {
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)
}
}
// The callback to handle data message received via FCM for devices running iOS 10 or above.
@objc(applicationReceivedRemoteMessage:) func application(received remoteMessage: MessagingRemoteMessage) {
print(remoteMessage.appData)
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
let isFBOpenUrl = FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
let isGoogleOpenUrl = GIDSignIn.sharedInstance().handle(url, sourceApplication: sourceApplication, annotation: annotation)
if isFBOpenUrl { return true }
if isGoogleOpenUrl { return true }
return false
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
if (url.host == "oauth-callback") {
OAuthSwift.handle(url: url)
}
return Twitter.sharedInstance().application(app, open: url, options: options)
return true
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) {
// ...
if error != nil {
// ...
return
}
guard let authentication = user.authentication else { return }
let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken, accessToken: authentication.accessToken)
// ...
}
func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) {
// Perform any operations when the user disconnects from app here.
// ...
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
@available(iOS 10, *)
extension AppDelegate : UNUserNotificationCenterDelegate {
// iOS10+, called when presenting notification in foreground
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
NSLog("[UserNotificationCenter] applicationState: \(applicationStateString) willPresentNotification: \(userInfo)")
//TODO: Handle foreground notification
completionHandler([.alert])
}
// iOS10+, called when received response (default open, dismiss or custom action) for a notification
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
NSLog("[UserNotificationCenter] applicationState: \(applicationStateString) didReceiveResponse: \(userInfo)")
//TODO: Handle background notification
completionHandler()
}
}
extension AppDelegate : MessagingDelegate {
func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
NSLog("[RemoteNotification] didRefreshRegistrationToken: \(fcmToken)")
}
// iOS9, called when presenting notification in foreground
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
NSLog("[RemoteNotification] applicationState: \(applicationStateString) didReceiveRemoteNotification for iOS9: \(userInfo)")
if UIApplication.shared.applicationState == .active {
//TODO: Handle foreground notification
} else {
//TODO: Handle background notification
}
}
}
最佳答案
删除对“GoogleService-Info.plist”文件的引用,然后使用添加到文件选项再次添加它...
关于ios - Swift Firebase 通知 "libc++abi.dylib: terminating with uncaught exception of type NSException",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46939014/
我看到这两个项目非常相关,但它们之间有什么区别?官方网页并没有说明太多。 我知道ABI(Application Binary Interface)用于在不同平台之间提供低级二进制接口(interfac
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 6年前关闭。 Improve thi
现代 glibc 二进制文件在 Linux 中称为 libc.so.6。为什么这里用“6”? libc.so.1 或 libc.so.8 也可以是好名字恕我直言。 维基百科在 http://en.wi
我在我的 Linux Mint 14 Nadia 中安装了 Matlab(a uname -a 显示:Linux Ideapad-Z570 3.5.0-17-generic#28-Ubuntu SMP
我有一个使用 eventfd 和 timerfd 内核系统调用的应用程序。为此,您需要一个现代内核和一个支持它们的 libc,至少是 2.8。 我目前的情况是,我的系统具有正确的内核,但是 2.7.1
我有一个用 musl libc 编译的共享库 $ readelf -d ./libinterop_d.so Dynamic section at offset 0x8ecb0 contains 22
我的问题是,是否总是需要 libc.a,即使我希望链接到 libc.so。我搜索了互联网,它给出了 3 个可能的答案(冲突) 1. c program will require to link to
我安装了多个版本的 libc,我如何在编译时选择要链接的对象? 现在我正在编译 g++ prog.cpp 最佳答案 您的程序将链接到 libc。当您在 gdb 中运行时,libc-dbg 将用于读取符
我在 Ubuntu 16.04 64 位上使用 gcc 5.4.0。当我编译程序时: gcc -o prog prog.c GCC 会自动链接到 C 标准库,因此我不必专门这样做。 我如何查看 gcc
我正在为我的系统安全类编写返回 libc 攻击。一、漏洞代码: //vuln.c #include #include int loadconfig(void){ char buf[1024];
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我正在尝试查找信息,但我没有在 clang 网站上看到它。我想尝试在 Windows 上使用它,但我不知道它是有自己的 libc 还是使用 MS 损坏的 libc? 另一个问题:如果我用 clang
我正在使用 clang 的规定通过插件和 clang 的 LibTooling 开发插件和工具。我能够做以下事情: 从 svn(Linux 和 OSX),通过运行配置脚本(不使用 cmake)按照入门
尝试运行时出现以下错误。 lib/libc.so.6:找不到(test.so)所需的版本“GLIBC_2.7” 要解决这个问题,在编译时静态链接到 libc-2.11.a 是否安全,这样在运行时就不会
首先,我在谷歌上搜索了很多,但没有找到与我的案例相关的任何东西,我有一个ELF可执行文件,我试图在我的Ubuntu WSL中运行它,我已经更改了权限(chmod+x文件),当我运行它时,显示以下错误。
GNU page说: Your program can arrange to run its own cleanup functions if normal termination happens.
我正在尝试在我的路由器上交叉编译 MIPSEL。我在汇编中找到了一些东西,但现在我开始尝试编译基本的 C 代码。 目前只有简单的 hello world c 代码,并使用 mipsel-linux-g
libc 中预期的字符编码是什么?例如,gethostname(char name, size_t namelen);以 char 作为参数。名称参数是否应该以 utf8(保持 ascii 完整)或纯
题 如果我包括 time.h ,更改“源类型参数”并重新包含该 header ,难道不应该添加这些新定义吗?我知道这是由于包括 guard 而发生的。我的问题是:这是 libc 中的错误吗?难道它不能
我正在学习Ubuntu上的动态链接器。我想导入我需要的libc函数,但是它链接了while libc.so文件。我不知道该怎么做,所以我来这里寻求帮助。 最佳答案 如果您将程序链接到动态库(例如 li
我是一名优秀的程序员,十分优秀!