显然,ios10现在可以实现这一点:
optional func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void)
Run Code Online (Sandbox Code Playgroud)
这个答案基本上说明了做这件事所需的工具:
当您的应用程序处于打开状态且位于前台时显示库存iOS通知横幅?
我只是不太了解如何将它们放在一起.
我不知道这有多重要,但我无法保留可选的func,xcode要我将其切换为私有.
我正试图展示徽章,文档提供
static var badge: UNNotificationPresentationOptions { get }
Run Code Online (Sandbox Code Playgroud)
这里很少丢失.
然后我假设我想要排除某个视图控制器获取这些徽章并且我没有使用导航控制器这个代码我发现它会起作用吗?:var窗口:UIWindow?
if let viewControllers = window?.rootViewController?.childViewControllers {
for viewController in viewControllers {
if viewController.isKindOfClass(MyViewControllerClass) {
print("Found it!!!")
}
}
}
Run Code Online (Sandbox Code Playgroud) ios uilocalnotification swift swift3 unusernotificationcenter
在我的SwiftUI项目中,我同时看到AppDelegate文件和SceneDelegate文件。
它们之间有什么区别?
例如,在 SceneDelegate
scene(_:willConnectTo:options:)
Run Code Online (Sandbox Code Playgroud)
并在 AppDelegate
application(_:didFinishLaunchingWithOptions:)
Run Code Online (Sandbox Code Playgroud) 我已经有一个可以完全使用 SwiftUI 构建的应用程序。我使用 Firebase 使用 Cloud Functions 进行身份验证和通知。
现在使用新的 SwiftUI App->Scene->View 构造,我无法将设置添加到我的应用程序中。
例如- >初期FirebaseApp.configure()将首先进去didFinishLaunchingWithOptions的AppDelegate,现在我在哪里添加此配置的损失。
设置远程通知也是如此。
PS:如果需要前一个应用程序的更多详细信息/代码,请发表评论。我没有添加任何代码,因为我觉得没有必要。
firebase firebase-authentication swiftui swiftui-environment
我正在开发一个 SwiftUI 应用程序,该应用程序仍然具有场景/应用程序委托文件,并希望将其迁移到新的 SwiftUI 应用程序协议。
这只是删除场景/应用程序委托文件,然后将我的 ContentView (在我的例子中为初始视图)添加到 @main 结构的问题吗?
谢谢你!
@main
struct TestApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Run Code Online (Sandbox Code Playgroud) 我想在我的应用程序处于前台时收到本地通知,当我尝试使用以下代码时,它永远不会触发通知,但是当我在后台输入应用程序时,它确实触发了。
这是我尝试过的:
//Schedule a Local Notification
func ScheduleNotification(timeInterval: Double, repeats: Bool, notificationBody:String, title:String){
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: timeInterval, repeats: repeats)
let center = UNUserNotificationCenter.current()
let identifier = "UYLLocalNotification"
let content = UNMutableNotificationContent()
content.title = title
content.body = notificationBody
content.sound = UNNotificationSound.default()
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
center.add(request, withCompletionHandler: { (error) in
if let error = error {
//Something went wrong
print(error.localizedDescription)
}
})
}
override func viewDidLoad() {
super.viewDidLoad()
if Currentcount < data.count {
self.ScheduleNotification(timeInterval: 5.0, …Run Code Online (Sandbox Code Playgroud) 我想知道为什么我们应该创建并使用带有 UIKit 生命周期的 SwiftUI 界面?我对此感到困惑!因为:
1-如果你想要 UIKit 编程,那么去选择 Storyboard 作为 Interface,然后选择 UIKit 作为 Life Cycle。
2-如果您想要 SwiftUI 编程,请选择 SwiftUI 作为接口,然后选择 SwiftUI 作为生命周期。
3-如果您想更改 Swift 语言,请将其更改为 Objective-C,您将获得 Storyboard 作为界面和 UIKit 作为生命周期。
选项 4 来了:
4-您可以将 SwiftUI for Interface 和 UIKit 作为生命周期!这就是这个问题的主题!如果我没记错的话,SwiftUI 处理的东西与 UIKit 不同,我们不需要在 SwiftUI 中定义委托或协议或类似的东西,但为什么我们在这种情况下得到AppDelegate和SceneDelegate !如果我们创建这样一个 Xcode 项目,有什么优点和缺点?
我正在构建一个带有电话号码登录的屏幕。我一遍又一遍地检查,该项目是新创建的,但是,我收到了以下日志:
7.2.0 - [Firebase/Auth][I-AUT000015] UIApplicationDelegate 必须处理远程通知才能使电话号码身份验证工作。如果 app delegate swizzling 被禁用,UIApplicationDelegate 收到的远程通知需要转发到 FIRAuth 的 canHandleNotificaton: 方法。
我确实阅读了有关 swizzling 的文档,但我不知道为什么它似乎被禁用了,我没有禁用它。我已将 GoogleServices-Info.plist 添加到应用程序中,我在 firebase 面板中添加了应用程序 apn auth 密钥。
我在应用程序中的入口点如下所示:
@main
struct partidulverdeApp: App {
init() {
FirebaseApp.configure()
}
var body: some Scene {
WindowGroup {
MainView()
.onOpenURL { url in
Auth.auth().canHandle(url.absoluteURL)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的 URL 类型属性有一个带有 RESERVED_CLIENT_ID 的条目
我对这个问题非常绝望。任何想法都受到高度赞赏。
编辑1:
我确实阅读了文档并尝试在禁用 swizzling 的情况下处理通知,但我遇到了同样的错误:
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication,
didReceiveRemoteNotification notification: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) …Run Code Online (Sandbox Code Playgroud) 是否可以在用户关闭最后一个窗口时关闭 macOS SwiftUI 应用程序,类似于applicationShouldTerminateAfterLastWindowClosedAppDelegate 函数。
func applicationShouldTerminateAfterLastWindowClosed(NSApplication) -> Bool
Run Code Online (Sandbox Code Playgroud)