• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 如何在设定的时间获得推送通知? ( swift 3)

[复制链接]
菜鸟教程小白 发表于 2022-12-12 13:17:08 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在制作一个应用程序,该应用程序假定用户每天在设定的时间了解新闻。它通过从数组调用它的函数获取新闻文本。我的问题是:如何让我的应用程序调用该函数,然后每天凌晨 4 点向我发送带有信息文本的推送通知?

感谢大家的回答!祝你有美好的一天!



Best Answer-推荐答案


这是我以前用过的一些代码。不是你要找的百分之一百,但我希望对你有用。

需要修改为每天发送

import UIKit
import UserNotifications
 
class ViewController: UIViewController, UNUserNotificationCenterDelegate {
    var isGrantedNotificationAccess:Bool = false
    @IBAction func send10SecNotification(_ sender: UIButton) {
        if isGrantedNotificationAccess {
            //add notification code here
         
            //Set the content of the notification
            let content = UNMutableNotificationContent()
            content.title = "10 Second Notification Demo"
            content.subtitle = "From MakeAppPie.com"
            content.body = "Notification after 10 seconds - Your pizza is Ready!!"
         
            //Set the trigger of the notification -- here a timer. 
            let trigger = UNTimeIntervalNotificationTrigger(
                timeInterval: 10.0,
                repeats: true)
         
            //Set the request for the notification from the above
            let request = UNNotificationRequest(
                identifier: "10.second.message",
                content: content,
                trigger: trigger
            )
         
            //Add the notification to the currnet notification center
            UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
         
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.sound,.badge]) { (granted, error) in
            self.isGrantedNotificationAccess = granted
        }
    }
}

关于ios - 如何在设定的时间获得推送通知? ( swift 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43148864/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap