philipphecht / react-native-doc-viewer

React Native Doc Viewer (Supports file formats: xls,ppt,doc,xlsx,pptx,csv,docx,png,jpg,pdf,xml,binary ...)
MIT License
94 stars 116 forks source link

Crash or Freeze on ios #101

Open amitbravo opened 6 years ago

amitbravo commented 6 years ago

"react-native": "^0.55.2", "react": "^16.3.1", "react-native-doc-viewer" : "2.7.8" and 2.7.7 and 2.7.3 tested too.

soon I click on click button , it throws this into xcode but no error in debugger or in emulator , either it makes app freeze or crash. Android working fine.

screen shot 2018-04-30 at 6 13 00 pm

code I tested


 import React, { Component } from 'react';
 import {
   AppRegistry,
   StyleSheet,
   Text,
   View,
   Platform,
   Button,
   Alert,
   ActivityIndicator,
   NativeAppEventEmitter,
   DeviceEventEmitter,
   NativeModules,
   NativeEventEmitter,
   TouchableHighlight
 } from 'react-native';
 import OpenFile from 'react-native-doc-viewer';
 var RNFS = require('react-native-fs');
 var SavePath = Platform.OS === 'ios' ? RNFS.MainBundlePath : RNFS.DocumentDirectoryPath;

export default class App extends Component<Props> {

  constructor(props) {
    super(props);
    this.state = {
      animating: false,
      progress: "",
      donebuttonclicked: false,
    }
    this.eventEmitter = new NativeEventEmitter(NativeModules.RNReactNativeDocViewer);
    this.eventEmitter.addListener('DoneButtonEvent', (data) => {
      /*
      *Done Button Clicked
      * return true
      */
      console.log(data.close);
      this.setState({donebuttonclicked: data.close});
    })
      //this.didPressToObjcButton = this.didPressToObjcButton.bind(this);
  }

  componentDidMount(){
    // download progress
    // this.eventEmitter.addListener(
    //   'RNDownloaderProgress',
    //   (Event) => {
    //     console.log("Progress - Download "+Event.progress  + " %")
    //     this.setState({progress: Event.progress + " %"});
    //   }
    //
    // );
  }

  componentWillUnmount (){
    this.eventEmitter.removeListener();
  }

  clickButton(){

    console.log('hithere')

    OpenFile.openDoc([{
        url:"http://www.pdf995.com/samples/pdf.pdf",
        fileNameOptional:"testfilename"
      }], (error, url) => {
         if (error) {
          this.setState({animating: false});
         } else {
          this.setState({animating: false});
           console.log(url)
         }
       })

  }

  render() {
    return (
      <View style={styles.container}>

        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>

              <Button
              onPress={()=>this.clickButton()}
              title="Learn More"
              color="#841584"
              accessibilityLabel="Learn more about this purple button"
              />

      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

crash with 2.7.3 and 2.7.8 with following error

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'You must override the `supportedEvents` method of fir_0x600000289fb0_RNReactNativeDocViewer'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000110d971e6 __exceptionPreprocess + 294
    1   libobjc.A.dylib                     0x000000011029e031 objc_exception_throw + 48
    2   CoreFoundation                      0x0000000110d9c472 +[NSException raise:format:arguments:] + 98
    3   Foundation                          0x000000010fd7764f -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 165
    4   myapp                         0x00000001072c4fe5 +[RCTEventEmitter initialize] + 325
    5   libobjc.A.dylib                     0x000000011029eb04 CALLING_SOME_+initialize_METHOD + 19
    6   libobjc.A.dylib                     0x000000011029ee9e _class_initialize + 276
    7   libobjc.A.dylib                     0x000000011029c2f3 object_setClass + 90
    8   myapp                         0x00000001078b1a1b -[FIRObjectSwizzler swizzle] + 145
    9   myapp                         0x000000010784b6ae __52-[FPRNSURLSessionDelegateInstrument registerObject:]_block_invoke + 888
    10  libdispatch.dylib                   0x00000001124ec848 _dispatch_client_callout + 8
    11  libdispatch.dylib                   0x00000001124f35b8 _dispatch_queue_barrier_sync_invoke_and_complete + 374
    12  myapp                         0x000000010784b30f -[FPRNSURLSessionDelegateInstrument registerObject:] + 121
    13  myapp                         0x000000010784e8c4 __InstrumentSessionWithConfigurationDelegateDelegateQueue_block_invoke + 225
    14  myapp                         0x0000000107222f25 -[RNReactNativeDocViewer hitServerForUrl:] + 165
    15  myapp                         0x000000010721fadf -[RNReactNativeDocViewer openDoc:callback:] + 223
    16  CoreFoundation                      0x0000000110d1accc __invoking___ + 140
    17  CoreFoundation                      0x0000000110d1ab84 -[NSInvocation invoke] + 308
    18  CoreFoundation                      0x0000000110d338d6 -[NSInvocation invokeWithTarget:] + 54
    19  myapp                         0x00000001072c487c -[RCTModuleMethod invokeWithBridge:module:arguments:] + 2796
    20  myapp                         0x000000010737a2f2 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 786
    21  myapp                         0x0000000107379e1f _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 127
    22  myapp                         0x0000000107379d99 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 25
    23  libdispatch.dylib                   0x00000001124eb807 _dispatch_call_block_and_release + 12
    24  libdispatch.dylib                   0x00000001124ec848 _dispatch_client_callout + 8
    25  libdispatch.dylib                   0x00000001124f792b _dispatch_main_queue_callback_4CF + 628
    26  CoreFoundation                      0x0000000110d59c99 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    27  CoreFoundation                      0x0000000110d1dea6 __CFRunLoopRun + 2342
    28  CoreFoundation                      0x0000000110d1d30b CFRunLoopRunSpecific + 635
    29  GraphicsServices                    0x0000000113654a73 GSEventRunModal + 62
    30  UIKit                               0x000000010d1dd0b7 UIApplicationMain + 159
    31  myapp                         0x0000000106fc8abf main + 111
    32  libdyld.dylib                       0x0000000112569955 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 
amitbravo commented 6 years ago

it may sound stupid but I found a solution for this, I do not know how it worked. I was using react-native-firebase too in the podfile . instead of using all modules as below

pod 'Firebase/Core'
  pod 'Firebase/AdMob'
  pod 'Firebase/Analytics'
  pod 'Firebase/Auth'
  pod 'Firebase/Crash'
  pod 'Firebase/Database'
  pod 'Firebase/DynamicLinks'
  pod 'Firebase/Messaging'
  pod 'Firebase/RemoteConfig'
  pod 'Firebase/Storage'
  pod 'Firebase/Firestore'
  pod 'Firebase/Performance'

I kept only essential modules as

pod 'Firebase/Core'
  pod 'Firebase/Auth'
  pod 'Firebase/Database'
  pod 'Firebase/Messaging'
  pod 'Firebase/Storage'
  pod 'Firebase/Firestore'

I deleted pod folder , reinstall pod and it worked.

Kylin93CN commented 6 years ago

use "$ react-native link react-native-doc-viewer" ,it is simple i think.

scanifydevo commented 6 years ago

@amitbravo exactly same issue.

but your solution is not working. any ideas?