gpt4 book ai didi

swift - 在 Swift 3 中,应用程序提交了注册 ios 8.1 的通知

转载 作者:行者123 更新时间:2023-11-30 12:08:57 25 4
gpt4 key购买 nike

以下是应用程序在注册通知时抛出错误时的错误详细信息:

<EXPR>:3:1: error: expected member name or constructor call after type name
Error
^

<EXPR>:3:1: note: use '.self' to reference the type object
Error
^
.self

这是在iOS 10.1中成功运行的代码

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error)
{
print("Failed to register Notification Error = ", Error)
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
{
print("Device Token = ", Data)
}



func registerForRemoteNotification()
{
if #available(iOS 10.0, *)
{

let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: [.sound, .alert, .badge])
{ (granted, error) in
if error == nil
{
UIApplication.shared.registerForRemoteNotifications()


}
}
}
else
{
if #available(iOS 8.0, *)
{
UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil))
UIApplication.shared.registerForRemoteNotifications()

}
else
{
UIApplication.shared.registerForRemoteNotifications(matching: [.badge, .sound, .alert])
}
}
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
{

if let dicAps = notification.request.content.userInfo["aps"] as? NSDictionary
{
AppUtilities.showAlertWithMessage(title: APP_TITLE as NSString, message: "\(dicAps.object(forKey: "msg")!)" as NSString)
}
completionHandler([.alert, .badge, .sound])
}

//Called to let your app know which action was selected by the user for a given notification.
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
{
print("User Info = ",response.notification.request.content.userInfo)
}

我正在尝试实现一个在 iOS 8 到 10.1 上运行的应用程序。它在装有 iOS 10.1.1 的 iPhone 5s 上运行良好。但是当我在 iOS 8.1 的模拟器中运行该应用程序时,它总是抛出上述错误,如果我遗漏了什么,请纠正我。

谢谢。

最佳答案

抱歉,您需要找到一些硬件来测试此功能。

推送通知在模拟器中不可用。它们需要来自 iTunes Connect 的配置文件,因此需要安装在设备上。这也意味着您可能需要加入 Apple iPhone 开发者计划并支付 99 美元。

来源:How can I test Apple Push Notification Service without an iPhone?

关于swift - 在 Swift 3 中,应用程序提交了注册 ios 8.1 的通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46313304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com