我正在关注firebase提供的sampler项目.
Firebase Cloud Messaging sammple
我的app代表是
import UIKit
import Firebase
import FirebaseMessaging
import UserNotifications
import FirebaseInstanceID
//add firebase code app delegate code
@UIApplicationMain
class AppDelegate: UIResponder,UIApplicationDelegate {
var window: UIWindow?
let gcmMessageIDKey = "gcm.message_id"
func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
// Register for remote notifications. This shows a permission dialog on first run,to
// show the dialog at a more appropriate time move this registration accordingly.
// [START register_for_notifications]
if #available(iOS 10.0,*) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert,.badge,.sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,completionHandler: {_,_ in })
<