ocetnik / react-native-background-timer

Emit event periodically (even when app is in the background)
MIT License
1.61k stars 226 forks source link

Background timer stopped after 30 seconds on iOS 13.3 & 13.3.1 #191

Open iamtharin opened 4 years ago

iamtharin commented 4 years ago

In iOS 13.3 & 13.3.1, when the count down timer is running in the background, it will be paused after 30s.

  1. Start a 60s count down timer in the foreground.
  2. After 10s, Put the app in the background (at 50s).
  3. Wait for 40s, while the app is in the background.
  4. Come to the foreground back.
  5. The count down timer starts to run from 20s but expected to be run from 10s.

Guys... Do you have any idea?

Zilleabbas10 commented 4 years ago

@iamtharin I have fixed this with the following solution.

<key>UIBackgroundModes</key>
<array>
  <string>audio</string>
</array>

Add this in Info.Plist of your project and it will work

iamtharin commented 4 years ago

@Zilleabbas10 We have already added it but the issue is there :(

gunduzcihat commented 4 years ago

it doesn't work on iOS 12.1.4

my code:

 import React, { Component } from 'react';
 import {
 SafeAreaView,
  Text,
  StatusBar,
 TouchableHighlight,
 Alert,
 } from 'react-native';
  import BackgroundTask from 'react-native-background-task'
  import queueFactory from 'react-native-queue';
  import { Notifications } from "react-native-notifications";
  import BackgroundTimer from 'react-native-background-timer';

  export default class App extends Component {
   constructor(props) {
     super(props);
     this.state = {
       isOpened: false,
       queue: null
     }

    Notifications.registerRemoteNotifications();

 Notifications.events().registerNotificationReceivedForeground((notification: Notification, completion: (response: NotificationCompletion) => void) => {
  Alert.alert('Bildirimler gelecek', '', [{ text: 'Kapat' }]);
  console.warn("Notification Received - Foreground", notification.payload);
  // Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
  completion({alert: true, sound: true, badge: true});
    });

Notifications.events().registerNotificationOpened((notification: Notification, completion: () => void, action: NotificationActionResponse) => {
  Alert.alert('bildirim açıldı!');
  console.warn("Notification opened by device user", notification.payload);
  completion();
});

    Notifications.events().registerNotificationReceivedBackground((notification: Notification, completion: (response: NotificationCompletion) => void) => {
  console.log("Notification Received - Background", notification.payload);

  // Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
  completion({alert: true, sound: true, badge: false});
  });
   }

   componentDidMount() {
     BackgroundTimer.start();
     setInterval(() => {
       return Notifications.postLocalNotification({
         body: "Tahmini 15 dk sonra gelen bildirim: 10:15",
         title: "Local Notification Title",
         sound: "chime.aiff",
         silent: false,
         category: "SOME_CATEGORY",
         userInfo: { }
       }, 3);
     }, 1000 * 10);
     BackgroundTimer.stop();
   }

   render() {
     return (
       <>
       <StatusBar barStyle="dark-content" />
       <SafeAreaView style={{ flex: 1, alignItems: 'center', justifyContent: 'center', }}>
           <Text>Deneme</Text>
       </SafeAreaView>
       </>
     )
   }
 }
tal987 commented 4 years ago

@gunduzcihat @iamtharin did you guys find any solution for iOS?

iamtharin commented 4 years ago

We had to do a work around. What we did was, playing a silent audio while the app is in the background mode. This worked as expected.

On Wed, May 6, 2020, 6:49 PM tal987 notifications@github.com wrote:

@gunduzcihat https://github.com/gunduzcihat @iamtharin https://github.com/iamtharin did you guys find any solution for iOS?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ocetnik/react-native-background-timer/issues/191#issuecomment-624644084, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOSY6LWO7RL4WCJPG57ZR3LRQFPVLANCNFSM4KY7N35A .

tal987 commented 4 years ago

@iamtharin can you show how did you do that please? how did you play silent sound?

tal987 commented 4 years ago

@iamtharin this is what you did? BackgroundTimer.runBackgroundTimer(() => { var fakeSound = new Sound('', Sound.MAIN_BUNDLE, (error) => { if (error) { console.log('failed to load the sound'); } }) fakeSound.play((success) => { if (success) { } else { } }); console.log("App is Hii") }, 3000*10);

jknap commented 4 years ago

Any news on this issue?

Also reproduced on iOS 12.4.8

d0xi5 commented 3 years ago

Nothing yet?

thanhluantl2304 commented 3 years ago

@iamtharin I have fixed this with the following solution.

<key>UIBackgroundModes</key>
<array>
  <string>audio</string>
</array>

Add this in Info.Plist of your project and it will work

This worked for me, very strange, because i set location before but didn't work

nguyentrannhan commented 3 years ago

+1, stop after 30 seconds

gpminsuk commented 3 years ago

@iamtharin I have fixed this with the following solution.

<key>UIBackgroundModes</key>
<array>
  <string>audio</string>
</array>

Add this in Info.Plist of your project and it will work

This worked for me, very strange, because i set location before but didn't work

I've tried this and got this message back from Apple.

Your app declares support for audio in the UIBackgroundModes key in your Info.plist, but we were unable to play any audible content when the app was running in the background.
Amar-RN commented 3 years ago

We had to do a work around. What we did was, playing a silent audio while the app is in the background mode. This worked as expected. On Wed, May 6, 2020, 6:49 PM tal987 @.***> wrote: @gunduzcihat https://github.com/gunduzcihat @iamtharin https://github.com/iamtharin did you guys find any solution for iOS? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#191 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOSY6LWO7RL4WCJPG57ZR3LRQFPVLANCNFSM4KY7N35A .

helo , how did you apply silent audio in bg. pls help me i am stuck in this issue last two week, can you give your contact or pls call on 8423087803, i need your helo

iamtharin commented 3 years ago

When the user is going to the background, a silent audio will be played until the user comes back from the background to the foreground. That's all what we did.

On Thu, Aug 12, 2021, 11:57 AM Amar-RN @.***> wrote:

We had to do a work around. What we did was, playing a silent audio while the app is in the background mode. This worked as expected. … <#m1910379230135917114> On Wed, May 6, 2020, 6:49 PM tal987 @.***> wrote: @gunduzcihat https://github.com/gunduzcihat https://github.com/gunduzcihat @iamtharin https://github.com/iamtharin https://github.com/iamtharin did you guys find any solution for iOS? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#191 (comment) https://github.com/ocetnik/react-native-background-timer/issues/191#issuecomment-624644084>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOSY6LWO7RL4WCJPG57ZR3LRQFPVLANCNFSM4KY7N35A .

helo , how did you apply silent audio in bg. pls help me i am stuck in this issue last two week, can you give your contact or pls call on 8423087803, i need your helo

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ocetnik/react-native-background-timer/issues/191#issuecomment-897382922, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOSY6LQRONGQ2KVUKISUI6TT4NSW3ANCNFSM4KY7N35A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

Amar-RN commented 3 years ago

can u share your contact no ? please please

if you dont mind.

On Thu, 12 Aug 2021 at 12:14, iamtharin @.***> wrote:

When the user is going to the background, a silent audio will be played until the user comes back from the background to the foreground. That's all what we did.

On Thu, Aug 12, 2021, 11:57 AM Amar-RN @.***> wrote:

We had to do a work around. What we did was, playing a silent audio while the app is in the background mode. This worked as expected. … <#m1910379230135917114> On Wed, May 6, 2020, 6:49 PM tal987 @.***> wrote: @gunduzcihat https://github.com/gunduzcihat https://github.com/gunduzcihat @iamtharin https://github.com/iamtharin https://github.com/iamtharin did you guys find any solution for iOS? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#191 (comment) < https://github.com/ocetnik/react-native-background-timer/issues/191#issuecomment-624644084

, or unsubscribe

https://github.com/notifications/unsubscribe-auth/AOSY6LWO7RL4WCJPG57ZR3LRQFPVLANCNFSM4KY7N35A .

helo , how did you apply silent audio in bg. pls help me i am stuck in this issue last two week, can you give your contact or pls call on 8423087803, i need your helo

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub < https://github.com/ocetnik/react-native-background-timer/issues/191#issuecomment-897382922 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AOSY6LQRONGQ2KVUKISUI6TT4NSW3ANCNFSM4KY7N35A

. Triage notifications on the go with GitHub Mobile for iOS < https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675

or Android < https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ocetnik/react-native-background-timer/issues/191#issuecomment-897389943, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATU7BUGXA66KWTS67LUG7OTT4NUUFANCNFSM4KY7N35A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

Amar-RN commented 3 years ago

Please call on 8423087803 or what app i need your help.

On Thu, 12 Aug 2021 at 12:55, Amar Gupta @.***> wrote:

can u share your contact no ? please please

if you dont mind.

On Thu, 12 Aug 2021 at 12:14, iamtharin @.***> wrote:

When the user is going to the background, a silent audio will be played until the user comes back from the background to the foreground. That's all what we did.

On Thu, Aug 12, 2021, 11:57 AM Amar-RN @.***> wrote:

We had to do a work around. What we did was, playing a silent audio while the app is in the background mode. This worked as expected. … <#m1910379230135917114> On Wed, May 6, 2020, 6:49 PM tal987 @.***> wrote: @gunduzcihat https://github.com/gunduzcihat https://github.com/gunduzcihat @iamtharin https://github.com/iamtharin https://github.com/iamtharin did you guys find any solution for iOS? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#191 (comment) < https://github.com/ocetnik/react-native-background-timer/issues/191#issuecomment-624644084

, or unsubscribe

https://github.com/notifications/unsubscribe-auth/AOSY6LWO7RL4WCJPG57ZR3LRQFPVLANCNFSM4KY7N35A .

helo , how did you apply silent audio in bg. pls help me i am stuck in this issue last two week, can you give your contact or pls call on 8423087803, i need your helo

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub < https://github.com/ocetnik/react-native-background-timer/issues/191#issuecomment-897382922 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AOSY6LQRONGQ2KVUKISUI6TT4NSW3ANCNFSM4KY7N35A

. Triage notifications on the go with GitHub Mobile for iOS < https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675

or Android < https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ocetnik/react-native-background-timer/issues/191#issuecomment-897389943, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATU7BUGXA66KWTS67LUG7OTT4NUUFANCNFSM4KY7N35A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

Amar-RN commented 3 years ago

hey,

How did you do , can u please share code.

On Thu, 12 Aug 2021 at 12:14, iamtharin @.***> wrote:

When the user is going to the background, a silent audio will be played until the user comes back from the background to the foreground. That's all what we did.

On Thu, Aug 12, 2021, 11:57 AM Amar-RN @.***> wrote:

We had to do a work around. What we did was, playing a silent audio while the app is in the background mode. This worked as expected. … <#m1910379230135917114> On Wed, May 6, 2020, 6:49 PM tal987 @.***> wrote: @gunduzcihat https://github.com/gunduzcihat https://github.com/gunduzcihat @iamtharin https://github.com/iamtharin https://github.com/iamtharin did you guys find any solution for iOS? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#191 (comment) < https://github.com/ocetnik/react-native-background-timer/issues/191#issuecomment-624644084

, or unsubscribe

https://github.com/notifications/unsubscribe-auth/AOSY6LWO7RL4WCJPG57ZR3LRQFPVLANCNFSM4KY7N35A .

helo , how did you apply silent audio in bg. pls help me i am stuck in this issue last two week, can you give your contact or pls call on 8423087803, i need your helo

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub < https://github.com/ocetnik/react-native-background-timer/issues/191#issuecomment-897382922 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AOSY6LQRONGQ2KVUKISUI6TT4NSW3ANCNFSM4KY7N35A

. Triage notifications on the go with GitHub Mobile for iOS < https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675

or Android < https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ocetnik/react-native-background-timer/issues/191#issuecomment-897389943, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATU7BUGXA66KWTS67LUG7OTT4NUUFANCNFSM4KY7N35A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

akimabs commented 2 years ago

any update ?

lowright commented 10 months ago

hey, i have the same error, stop working after 30sec