Swift中的远程通知没有声音

时间:2016-07-17 09:47:43

标签: ios swift google-cloud-messaging apple-push-notifications

我正在使用GCM向我的ios应用发送苹果推送通知,通知效果不错但没有声音。
我该如何解决这个问题呢? 这是我的代码:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

    // Preloads keyboard so there's no lag on initial keyboard appearance.
    let lagFreeField:UITextField = UITextField();

    self.window?.addSubview(lagFreeField);
    lagFreeField.becomeFirstResponder();
    lagFreeField.resignFirstResponder();
    lagFreeField.removeFromSuperview();

    locationManager = CLLocationManager()
    locationManager?.requestWhenInUseAuthorization()

    var configureError:NSError?
    GGLContext.sharedInstance().configureWithError(&configureError)
    assert(configureError == nil, "Error configuring Google services: \(configureError)")
    gcmSenderID = GGLContext.sharedInstance().configuration.gcmSenderID

    if #available(iOS 8.0, *) {
        let settings: UIUserNotificationSettings =
            UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound.union(UIUserNotificationType.Alert), categories: nil)
        application.registerUserNotificationSettings(settings)
        application.registerForRemoteNotifications()
    } else {
        let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
        UIApplication.sharedApplication().registerUserNotificationSettings(settings)
        UIApplication.sharedApplication().registerForRemoteNotifications()
    }
    let gcmConfig = GCMConfig.defaultConfig()
    gcmConfig.receiverDelegate = self
    GCMService.sharedInstance().startWithConfig(gcmConfig)
    return true
}

1 个答案:

答案 0 :(得分:2)

问题在于Google云消息传递。它们仅支持声音标签的“默认”值。因此,每当我将其更改为任何内容时,GCM服务器根本不会发送声音标记。 cloud-messaging enter image description here