Browse Source

Add IOS support #115

Ben Hsieh 7 years ago
parent
commit
e24a476e56
2 changed files with 15 additions and 1 deletions
  1. 8
    1
      src/index.js
  2. 7
    0
      src/ios/RNFetchBlob/RNFetchBlob.m

+ 8
- 1
src/index.js View File

@@ -9,6 +9,7 @@ import {
9 9
   NativeAppEventEmitter,
10 10
   Platform,
11 11
   AsyncStorage,
12
+  AppState,
12 13
 } from 'react-native'
13 14
 import type {
14 15
   RNFetchBlobNative,
@@ -44,7 +45,13 @@ const {
44 45
 
45 46
 const Blob = polyfill.Blob
46 47
 const emitter = DeviceEventEmitter
47
-const RNFetchBlob= NativeModules.RNFetchBlob
48
+const RNFetchBlob = NativeModules.RNFetchBlob
49
+
50
+AppState.addEventListener('change', (e) => {
51
+  console.log('app state changed', e)
52
+  if(e === 'active')
53
+    RNFetchBlob.emitExpiredEvent(()=>{})
54
+})
48 55
 
49 56
 // register message channel event handler.
50 57
 emitter.addListener("RNFetchBlobMessage", (e) => {

+ 7
- 0
src/ios/RNFetchBlob/RNFetchBlob.m View File

@@ -486,5 +486,12 @@ RCT_EXPORT_METHOD(getCookies:(NSString *)url resolver:(RCTPromiseResolveBlock)re
486 486
     resolve([RNFetchBlobNetwork getCookies:url]);
487 487
 })
488 488
 
489
+# pragma mark - check expired network events
490
+
491
+RCT_EXPORT_METHOD(emitExpiredEvent:(RCTResponseSenderBlock)callback
492
+{
493
+    [RNFetchBlobNetwork emitExpiredTasks];
494
+})
495
+
489 496
 
490 497
 @end