我的应用程序与Firebase服务器连接,也用于发送推送通知.现在,我想更进一步,为通知添加一个动作.在抛出大量教程之后,它仍然不适合我.操作按钮未显示,您可以在此处看到:
这是我的代码:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.applicationIconBadgeNumber = 0
FirebaseApp.configure()
registerForPushNotifications()
return true
}
func registerForPushNotifications() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {
(granted, error) in
print("Permission granted: \(granted)")
guard granted else { return }
let viewAction = UNNotificationAction(identifier: "addToCal",
title: "Zum Kalender hinzufügen",
options: [.foreground])
let newsCategory = UNNotificationCategory(identifier: "NEW_SESSION",
actions: [viewAction],
intentIdentifiers: [],
options: [])
UNUserNotificationCenter.current().setNotificationCategories([newsCategory])
self.getNotificationSettings()
}
}
func getNotificationSettings() {
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
print("Notification settings: \(settings)")
guard settings.authorizationStatus == …
Run Code Online (Sandbox Code Playgroud) push-notification apple-push-notifications ios firebase swift
在 iOS 9 中,开发人员可以使用UIKeyCommand将快捷方式添加到 iPad 应用程序。这些是在外部键盘上输入的,并且函数会做出反应。
有没有办法在mac上的模拟器中测试这些?或者像这样展示它们:
自从在 Xcode 8 (Beta 1) 和 Swift 3 上升级后,我在这一行中出现错误:
account.requestAccessToAccounts(with: accountType, options: nil, completion: {(success: Bool, error: NSError!) -> Void in
Run Code Online (Sandbox Code Playgroud)
它说:
无法将 '(Bool, NSError!) -> Void' 类型的值转换为预期的参数类型 'ACAccountStoreRequestAccessCompletionHandler!'
在该行之前,我定义了“account”和“accountType”:
let account = ACAccountStore()
let accountType = account.accountType(
withAccountTypeIdentifier: ACAccountTypeIdentifierTwitter)
Run Code Online (Sandbox Code Playgroud)
这是我的(使用 Xcode 7 和 Swift 2 工作)代码:
func getTimeline() {
//https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi&count=2
let account = ACAccountStore()
let accountType = account.accountType(
withAccountTypeIdentifier: ACAccountTypeIdentifierTwitter)
account.requestAccessToAccounts(with: accountType, options: nil,
completion: {(success: Bool, error: NSError!) -> Void in
if success {
let arrayOfAccounts =
account.accounts(with: …
Run Code Online (Sandbox Code Playgroud) 自从在Xcode 8(Beta 1)和Swift 3上升级后,我在此行中出错:
class CloudViewController: UIViewController, WCSessionDelegate {
Run Code Online (Sandbox Code Playgroud)
它说 :
类型'UIViewController'不符合协议'WCSessionDelegate'
这是我的(使用Xcode 7和Swift 2)代码:
override func viewDidLoad() {
super.viewDidLoad()
if(WCSession.isSupported()){
self.session = WCSession.default()
self.session.delegate = self
self.session.activate()
}
}
func session(_ session: WCSession, didReceiveMessage message: [String : AnyObject]) {
print("didReceiveMessage")
watchMessageHandler.getMessage(message)
}
Run Code Online (Sandbox Code Playgroud)
此错误也会显示在WKInterfaceController类中.