iOS“本地”推送通知 [英] iOS "Local" Push Notification

查看:114
本文介绍了iOS“本地”推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来制作本地推送通知。我无法弄清楚我应该怎么做,所以我正在寻求一些帮助。我需要的是:

I'm looking for a way to make "local" push notifications. I can't figure out how I should do this, so I'm looking for some help. What I need is:


  • 一种为24小时内未打开应用程序的用户发送通知的方法。 (或者 int 没有变化)

  • a way to send a notification for a user who haven't opened the application within 24 hours. (Or that an int havent change)

我真的希望你们中的一个有时间来帮助我,谢谢!

I really hope that one of you got time to help me, thanks!

推荐答案

这很简单:

1 )当应用程序关闭时,安排一个本地通知,这将在24小时内火

1) When the app is closed, schedule a local notification that will fire in 24 hours

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    UILocalNotification *notification = [[UILocalNotification alloc] init];
    notification.fireDate = [[NSDate date] dateByAddingTimeInterval:60*60*24];
    notification.alertBody = @"24 hours passed since last visit :(";
    [[UIApplication sharedApplication] scheduleLocalNotification:notification];
}

2)如果应用程序已打开(在本地通知触发之前),请取消本地通知

2) if the app is opened (before the local notification fires), cancel the local notification

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
}

这篇关于iOS“本地”推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆