steste95
steste95

Reputation: 35

Notifications when App runs in Background

I've a timer who's checking every 10 seconds for e new Message (awesome_notifications). So this works on Android and the iOS-Simulator, no matter if the app is opened or runs in the background. Only installed in the physically iPhone it's working just when the app is open - the push notification appears as soon as the app is opened. What to do?

      @override
 void dispose() {
 timer?.cancel();
 super.dispose();
 }

Timer? timer;
@override
void initState() {
super.initState();
timer = Timer.periodic(Duration(seconds: 10), (Timer t) => 
 NotificationController().notificationCheck());
}

Upvotes: 0

Views: 68

Answers (1)

kirander
kirander

Reputation: 2256

You need to use some background mode to keep the app running in the background. Timers are not enough for that. I think, in your case you have 2 options:

  1. Background fetch, where app periodically fetch new information from the internet or API server.
  2. Remote or push notifications. Own server, Firebase or any push notification service required.

Usually for message system push notifications are used. Background fetch is more for less frequent information, like daily news.

Upvotes: 1

Related Questions