标签: uilocalnotification

本地通知"didReceiveLocalNotification"调用两次

我使用以下方式处理本地通知:

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif
Run Code Online (Sandbox Code Playgroud)

并安排本地通知:

- (void)scheduleNotificationWithInterval:(int)minutesBefore {
    UILocalNotification *localNotif = [[UILocalNotification alloc] init];

    if (localNotif == nil)
        return;

    NSDate *fireDate = [NSDate date];
    localNotif.fireDate = [fireDate dateByAddingTimeInterval:minutesBefore*60];
    localNotif.timeZone = [NSTimeZone defaultTimeZone];
    localNotif.repeatInterval = kCFCalendarUnitMinute;
    localNotif.alertBody = [NSString stringWithFormat:NSLocalizedString(@"LocalEvent notification in %i minutes.", nil),minutesBefore];
    localNotif.alertAction = NSLocalizedString(@"View Details", nil);
    localNotif.applicationIconBadgeNumber = 1;

    NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"This is dict, you can pass info for your notification",@"info",nil];
    localNotif.userInfo = infoDict;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

    [localNotif release];
    NSLog(@"Event scheduled");
}
Run Code Online (Sandbox Code Playgroud)

当我收到通知时, …

iphone notifications ios uilocalnotification

13
推荐指数
2
解决办法
1万
查看次数

申请终止的本地通知

我正在开发一个应用程序,如果终止它将无法工作.它有一些后台任务.如果应用程序被终止,我想显示本地通知.有些应用程序执行此操作意味着这是可行的.但我无法找到方法.

我试图在applicationWillTerminate:appdelegate的方法中设置本地通知,并在我的viewcontroller中添加了应用终止的通知,但是当app实际终止时,没有任何方法被调用.

- (void)applicationWillTerminate:(UIApplication *)application
{
    NSLog(@"terminated");
    UIApplication * app = [UIApplication sharedApplication];
    NSDate *date = [[NSDate date] dateByAddingTimeInterval:15];
    UILocalNotification *alarm = [[UILocalNotification alloc] init] ;
    if (alarm) {
        alarm.fireDate = [NSDate date];
        alarm.timeZone = [NSTimeZone defaultTimeZone];
        alarm.repeatInterval = 0;
        alarm.alertBody = @"This app does not work if terminated";
        alarm.alertAction = @"Open";
        [app scheduleLocalNotification:alarm];
    }

    [app presentLocalNotificationNow:alarm];
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
Run Code Online (Sandbox Code Playgroud)

任何帮助都会很棒.

提前致谢 !!!

iphone uiapplicationdelegate uilocalnotification

13
推荐指数
3
解决办法
1万
查看次数

自定义报警的UILocalNotification重复间隔(太阳,周一,周二,周三,星期四,星期五,坐着)

UILocalNotification用于报警目的.我有一个基于工作日重复的自定义选项(sun,mon,tue,wed,thu,fri,sat).许多应用程序都执行了此过程.我最好的尝试了我的水平.但我无法让它发挥作用.请各位帮帮我....

iphone nscalendar ipad ios uilocalnotification

12
推荐指数
1
解决办法
2万
查看次数

如何在ios sdk中识别特定通知

实际上我正在开发一个警报项目,现在我对本地通知有疑问.我如何识别特定通知.我们甚至无法将标签设置为本地通知,那么我如何区分它们.

例:

通知:1

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    localNotification.fireDate = selectedDate; 
    localNotification.alertBody = @"you got work";
    localNotification.alertAction = @"Snooze";
    localNotification.repeatInterval = NSDayCalendarUnit;
    localNotification.soundName = UILocalNotificationDefaultSoundName;

    NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"setNotificationForEveryDay", @"key", nil];
    localNotification.userInfo = infoDict;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
    [localNotification release];
Run Code Online (Sandbox Code Playgroud)

通知:2,

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    localNotification.fireDate = another selectedDate; 
    localNotification.alertBody = @"i got work";
    localNotification.alertAction = @"Snooze";
    localNotification.repeatInterval = NSDayCalendarUnit;
    localNotification.soundName = UILocalNotificationDefaultSoundName;
    NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"setNotificationForEveryDay", @"key", nil];
    localNotification.userInfo = infoDict;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
    [localNotification …
Run Code Online (Sandbox Code Playgroud)

ios uilocalnotification

12
推荐指数
1
解决办法
7264
查看次数

以编程方式从通知托盘中删除UILocalNotification

有没有办法以编程方式UILocalNotification从通知托盘中删除/解除.我可以取消删除通知的通知

[[UIApplication sharedApplication] scheduledLocalNotifications]
Run Code Online (Sandbox Code Playgroud)

这是我需要做的

我需要UILocalNotification在执行操作后(即在用户点击通知后)从NotificationTray中解除

编辑:我可以删除通知NSNotificationCenter.我想从通知托盘中删除特定通知.例如,用户按下清除按钮以清除属于特定应用程序的所有通知.

iphone objective-c ios uilocalnotification

12
推荐指数
3
解决办法
1万
查看次数

删除并重新安装iphone应用程序后接收本地通知

UILocalNotification在我的项目中使用.我使用的是一个问题UILocalNotifications.如果我安排一周的通知,删除应用程序并重新安装,而没有从重新安装的应用程序安排通知,我会收到先前安排的通知.

即使从当前安装中没有安排通知,我也会收到通知.有没有办法取消安排/删除这些通知?

iphone ios4 ios uilocalnotification

12
推荐指数
1
解决办法
2521
查看次数

清除应用程序的徽章编号

我已经在iPhone应用程序中进行了本地通知.并设置图标徽章编号.

一切都很好.但是如果我在托盘中有两个通知,用户点击清除按钮而不是从托盘中删除通知.

但图标的徽章编号保持不变.

我想将徽章编号设置为零.

谢谢.

iphone tray badge ios uilocalnotification

12
推荐指数
2
解决办法
1万
查看次数

NSCalendarUnitWeekOfYear和NSCalendarUnitWeekOfMonth之间的区别

我想UILocalNotification在iOS7之前每周重复一次,localNotification.repeatInterval = NSWeekCalendarUnit除非NSWeekCalendarUnit已被弃用.

文档说:

"使用NSCalendarUnitWeekOfMonth或NSCalendarUnitWeekOfYear,具体取决于您的意思"

但我不知道有什么区别,所以我不知道我的意思.

objective-c nscalendar ios uilocalnotification ios7

12
推荐指数
2
解决办法
4067
查看次数

尝试实现beginBackgroundTaskWithExpirationHandler和UILocalNotification

AppDelegate当我的应用程序进入后台时,我有以下代码:

var backgroundUpdateTask: UIBackgroundTaskIdentifier!

func beginBackgroundUpdateTask() {
    self.backgroundUpdateTask = UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler({
        self.endBackgroundUpdateTask()
    })
}

func endBackgroundUpdateTask() {
    UIApplication.sharedApplication().endBackgroundTask(self.backgroundUpdateTask)
    self.backgroundUpdateTask = UIBackgroundTaskInvalid
}

func doBackgroundTask() {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
        self.beginBackgroundUpdateTask()

        // Do something with the result.
        var timer = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: "displayAlert", userInfo: nil, repeats: false)
        NSRunLoop.currentRunLoop().addTimer(timer, forMode: NSDefaultRunLoopMode)
        NSRunLoop.currentRunLoop().run()

        // End the background task.
        self.endBackgroundUpdateTask()
    })
}

func displayAlert() {
    let note = UILocalNotification()
    note.alertBody = "As a test I'm hoping this will run in the background every …
Run Code Online (Sandbox Code Playgroud)

uilocalnotification uibackgroundtask swift

12
推荐指数
1
解决办法
5904
查看次数

如果在swift中忽略第一个通知(或者如果忽略通知则完成任何操作),则调度第二个通知

因此,我现在在应用程序商店中有一个应用程序,提前安排10个通知,假设您错过了一个,您仍将获得第二次机会或十个.在你认为我会打扰这个人之前,通知对于应用程序的功能非常重要,而且确实是主要目的.该应用程序是为iOS 7构建的,因此当时没有"handleActionWithIdentifier",根据我的理解,即使关闭应用程序,也可以完成对应用程序的操作,具体取决于用户对通知的响应.此更新对应用程序非常有用,因为它消除了我必须打开应用程序以响应通知的部分问题(通知询问用户一个问题,并根据答案,完成一些事情).

剩下的问题是检测是否错过了通知,如果通知被取消或忽略,我将如何显示另一个通知,例如第二天.我在google和堆栈溢出搜索了这个,根据我的理解,所有以前的问题一直在询问如何检测通知是否错过了应用程序打开,我不需要.

此时,如果用户通过按下通知中的一个选项来响应通知,则可以正常运行代码:

func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, withResponseInfo responseInfo: [NSObject : AnyObject], completionHandler: () -> Void) {
        var userInfo = [NSObject: AnyObject]()
        userInfo["text"] = responseInfo[UIUserNotificationActionResponseTypedTextKey]
        NSNotificationCenter.defaultCenter().postNotificationName("text", object: nil, userInfo: userInfo)

        print(userInfo)

        completionHandler()
    }
Run Code Online (Sandbox Code Playgroud)

截至目前,我只是采取文本输入并打印它,但如果我愿意,我可以发出第二个通知.有没有一种方法来检测何时错过通知并安排另一个通知?

总是有可能仍然不可能做我想要的事情,我只是预先安排10个通知,这看起来很草率,不让我做出反复的回应.

TLDR; 如果在未打开应用程序的情况下错过本地通知,如何检测并运行代码

顺便说一句:如果你有答案,swift是首选语言

iphone notifications ios uilocalnotification swift

12
推荐指数
1
解决办法
652
查看次数