小编Ale*_*xey的帖子

ios10,Swift 3和Firebase推送通知(FCM)

我正在努力显示我从FCM通知控制台发送到我的设备的推送通知.我可以看到设备正在接收通知,因为我可以看到我发送的消息"test8"

Connected to FCM.
%@ [AnyHashable("notification"): {
    body = test8;
    e = 1;
},
Run Code Online (Sandbox Code Playgroud)

但是,如果我的应用程序位于前台或后台并不显示通知,则无关紧要.

我已将"必需的后台模式 - 应用程序下载内容以响应推送通知"添加到info.plist.我的证书是正确的,我没有生成令牌的问题.我的应用程序正在接收通知,但只是没有显示它们.

import UIKit
import UserNotifications
import Firebase
import FirebaseInstanceID
import FirebaseMessaging

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        // [START register_for_notifications]
        if #available(iOS 10.0, *) {
            let authOptions : UNAuthorizationOptions = [.Alert, .Badge, .Sound]
            UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions(
                authOptions,
                completionHandler: {_,_ in })

            // For iOS 10 display notification (sent via APNS)
            UNUserNotificationCenter.currentNotificationCenter().delegate = …
Run Code Online (Sandbox Code Playgroud)

ios firebase swift firebase-cloud-messaging

5
推荐指数
1
解决办法
1万
查看次数

Swift 编译器挂起!这是一个错误吗?

有一次,当我正在开发 Swift 项目时,Xcode 的状态栏中出现了“编译 Swift 源代码”消息。无论等多久,编译都没有完成。我回滚了最近的更改,很快意识到让编译器感到困惑的是一个非常简单的枚举结构。下面是一个说明该问题的 Playground 示例。

创建一个新的 Playground 并粘贴此代码。你看到任何输出吗?

// Playground - noun: a place where people can play

import UIKit

enum FastingType: Int {
    case NoFast=0, Vegetarian, FishAllowed, FastFree, Cheesefare
}

class Fasting
{
    var allowedFood = [
        .NoFast:        ["meat", "fish", "milk", "egg", "cupcake"],
        .Vegetarian:    ["vegetables", "bread", "nuts"],
        .FishAllowed:   ["fish", "vegetables", "bread", "nuts"],
        .FastFree:      ["cupcake", "meat", "fish", "cheese"],
        .Cheesefare:    ["cheese", "cupcake", "milk", "egg"]
    ]

    func getAllowedFood(type: FastingType) -> [String] {
        return allowedFood[type]
    }
}


var fasting = …
Run Code Online (Sandbox Code Playgroud)

xcode swift ios8

4
推荐指数
1
解决办法
2177
查看次数

标签 统计

swift ×2

firebase ×1

firebase-cloud-messaging ×1

ios ×1

ios8 ×1

xcode ×1