最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]swift实现app的消息通知显示到桌面

Swift crifan 3348浏览 0评论

需要用swift实现,当app有新消息时,显示推送消息,通知,到桌面,点击后,可以进入到对应的消息界面或app的主界面。

swift notification push

iOS 8 Notifications in Swift

Xcode6 Swift add Remote Push Notifications and send from PHP – Stack Overflow

ios – How to setup push notifications in Swift – Stack Overflow

[How To] Setup Remote Push Notification in iOS – Swift 2.0 Code – YouTube

Push Notifications Tutorial for iOS 9 – Intertech Blog

Push Notifications in Swift for iOS 7 & 8

Swift Tutorial: Push Notification enabled app and .Net Based Push Notification Server

iOS Remote Notifications in Swift

swift 消息推送

Swift – 本地消息的推送通知(附样例)

细说 iOS 消息推送 | LeanCloud Blog

swift版本remote notification远程推送通知实现(ios8)

iOS推送小结–swift语言 – Maple023 – 博客园

加上了代码:

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
       
        //enable notification
        let notifSettings = UIUserNotificationSettings(forTypes: [UIUserNotificationType.Badge],
            categories: nil)
        application.registerUserNotificationSettings(notifSettings)
        return true
    }
    func sendNotification(newMessage:Message){
        if newMessage is TextMessage {
            let textMsg = newMessage as! TextMessage
           
            var notifBody = textMsg.text
            if !textMsg.senderName.isEmpty {
                notifBody = textMsg.senderName + ": " + notifBody
            }
            let localNotif = UILocalNotification()
            localNotif.fireDate = NSDate(timeIntervalSinceNow: 1)
            localNotif.timeZone = NSTimeZone.defaultTimeZone()
            localNotif.alertBody = notifBody
            UIApplication.sharedApplication().scheduleLocalNotification(localNotif)
        }
    }

运行后,出现提示:

然后有新消息来时,就可以收到桌面的那种通知了:

点击新消息后,进入app:

继续去解决:

[已解决]Swift中提醒用户是否授权发送通知消息时app名字为(null)

然后再去解决:

[已解决]swift中添加app消息通知桌面图标显示红色数字的支持

转载请注明:在路上 » [已解决]swift实现app的消息通知显示到桌面

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.196 seconds, using 22.07MB memory