首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有来自远程通知的声音

没有来自远程通知的声音
EN

Stack Overflow用户
提问于 2016-10-23 11:35:44
回答 1查看 659关注 0票数 0

有人能帮我理解一下为什么我没有收到IOS 10 Swift 3中远程通知的声音吗?

下面是我的代码: AppDelegate:

代码语言:javascript
复制
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]?) -> Bool {
        let settings = UNUserNotificationCenter.current()
        settings.requestAuthorization(options: [.badge, .alert, .sound]) {(granted, error) in
        }
    return true
    }

    // Override point for customization after application launch.
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
        let viewController = self.window?.rootViewController as! LoadingCloudDataViewController
        let notification: CKNotification = CKNotification(fromRemoteNotificationDictionary: userInfo as! [String: NSObject])
        if(notification.notificationType == CKNotificationType.query) {
            let queryNotification = notification as! CKQueryNotification
            let recordID = queryNotification.recordID
            viewController.fetchRecord(recordID: recordID!)
        }
    }

下面是通知订阅代码:

代码语言:javascript
复制
func subscriptionNotificationsKcal() {
        publicDatabase = container.publicCloudDatabase
        let predicate = NSPredicate(format: "TRUEPREDICATE")
        let subscription = CKQuerySubscription(recordType: "Kcal", predicate: predicate, options: .firesOnRecordCreation)
        let notificationInfo = CKNotificationInfo()
        notificationInfo.alertBody = "New Calories Item was Added"
        notificationInfo.shouldBadge = true
        subscription.notificationInfo = notificationInfo
        publicDatabase?.save(subscription, completionHandler: ({returnRecord, error in
            if let err = error {
                print("subscription failed %@", err.localizedDescription)
            }else{
                print("sub success")
            }
        }))
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-29 10:04:16

默认情况下,声音是静音的。要激活它,在本例中,使用以下代码:

代码语言:javascript
复制
notificattionInfo.soundName = "default"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40202449

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档