Local Notifications Call Separate Method

hmzfier

I'm trying to fire a local notification on repeated intervals, but I want it to call another method every time a notification is sent. Is that possible?

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil) return;

//Repeat every 60 seconds
NSDate *fireTime = [[NSDate date] dateByAddingTimeInterval:60]; 

localNotif.fireDate = fireTime;
localNotif.alertBody = @"Notification Sent!"; //send notification
localNotif.repeatInterval=kCFCalendarUnitMinute;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

//call method??

I want to call this method:

-(void) callAfterSixtySecond
{
    //do something
}
Ander

Yes and no. If the app is active when the notification fires then application:didReceiveLocalNotification: will be called in app delegate and you could use this to call the method. However, if the app is in the background then this method won't get called unless the user launches the app by tapping on the notification in Notification Center, and so it won't be when the notification first fires.

One way you could do this is to schedule the method separately with something like the following:

[self performSelector:@selector(callAfterSixtySecond) withObject:nil afterDelay:60];

This will work as long as the app still has processing time when the method should run. If the user has closed the app this it generally only has around 10s of processing time but in same cases this can be increased by starting a background task (see beginBackgroundTaskWithName:expirationHandler: in UIApplication).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

NSURLSessionUploadTask as separate method, but returning data to a call

From Dev

Call a mutator method from a separate class

From Dev

Python: How to call method in separate process

From Dev

NSURLSessionUploadTask as separate method, but returning data to a call

From Dev

Call boolean method statically from separate class

From Dev

Local Notifications

From Dev

Local Notifications

From Dev

Can Python Staticmethod Call Another Local Method?

From Dev

Call to local method from list comprehension failing

From Dev

Can I have a comment between an object and a method call on separate lines?

From Dev

Call a method without a reference to it from a separate jar library

From Dev

C# consoleApp Cannot call static method in separate class

From Dev

Cordova "Local Notifications" plugin?

From Dev

iOS and local Notifications

From Dev

Push notifications in a local network

From Dev

Geolocation, service and local notifications

From Dev

Local Notifications at a specific time

From Dev

Ios repeating local notifications

From Dev

Local Notifications using Firebase

From Dev

Local Notifications in Mobile Application

From Dev

Additional Vibrations for Push Notifications with Local Notifications

From Dev

Additional Vibrations for Push Notifications with Local Notifications

From Dev

How can I call local method in Linq to Entities query?

From Dev

Uncaught TypeError: Object local.process has no method 'call'

From Dev

How to call local variable value in a method through a parameter?

From Dev

How can I call local method in Linq to Entities query?

From Dev

Call local EJB method failds with java.lang.ClassCastException

From Dev

Does local call of an EJB abstract method open a new Transaction?

From Dev

How can I solve Call to undefined method Illuminate\Notifications\Messages\MailMessage::bcc() on laravel notification?

Related Related

  1. 1

    NSURLSessionUploadTask as separate method, but returning data to a call

  2. 2

    Call a mutator method from a separate class

  3. 3

    Python: How to call method in separate process

  4. 4

    NSURLSessionUploadTask as separate method, but returning data to a call

  5. 5

    Call boolean method statically from separate class

  6. 6

    Local Notifications

  7. 7

    Local Notifications

  8. 8

    Can Python Staticmethod Call Another Local Method?

  9. 9

    Call to local method from list comprehension failing

  10. 10

    Can I have a comment between an object and a method call on separate lines?

  11. 11

    Call a method without a reference to it from a separate jar library

  12. 12

    C# consoleApp Cannot call static method in separate class

  13. 13

    Cordova "Local Notifications" plugin?

  14. 14

    iOS and local Notifications

  15. 15

    Push notifications in a local network

  16. 16

    Geolocation, service and local notifications

  17. 17

    Local Notifications at a specific time

  18. 18

    Ios repeating local notifications

  19. 19

    Local Notifications using Firebase

  20. 20

    Local Notifications in Mobile Application

  21. 21

    Additional Vibrations for Push Notifications with Local Notifications

  22. 22

    Additional Vibrations for Push Notifications with Local Notifications

  23. 23

    How can I call local method in Linq to Entities query?

  24. 24

    Uncaught TypeError: Object local.process has no method 'call'

  25. 25

    How to call local variable value in a method through a parameter?

  26. 26

    How can I call local method in Linq to Entities query?

  27. 27

    Call local EJB method failds with java.lang.ClassCastException

  28. 28

    Does local call of an EJB abstract method open a new Transaction?

  29. 29

    How can I solve Call to undefined method Illuminate\Notifications\Messages\MailMessage::bcc() on laravel notification?

HotTag

Archive