Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont show modal on iOS #18

Closed
luisfuertes opened this issue Nov 30, 2016 · 48 comments
Closed

Dont show modal on iOS #18

luisfuertes opened this issue Nov 30, 2016 · 48 comments

Comments

@luisfuertes
Copy link

luisfuertes commented Nov 30, 2016

Hi, thanks for this component.

On iOS i think all its fine configured but when i press on share to MyAppShareEx, nothing happen. It dont show any popup.

Some idea? If need some code of my config ask me and i will post it.

Thanks!

@bengoism
Copy link

bengoism commented Dec 1, 2016

I have the exact same problem, would be great If we could figure out why :).. Im using React native v.0.37... @luisfuertes @alinz please ping me if you find a solution :)

@luisfuertes
Copy link
Author

My versions:

    "react": "15.3.2",
    "react-native": "0.33.0",
    "react-native-share-extension": "^1.0.3",

@TheSisb
Copy link

TheSisb commented Dec 6, 2016

Please share your code if you want help. The issue is relatively broad to guess from.

@luisfuertes
Copy link
Author

luisfuertes commented Dec 7, 2016

@TheSisb ofcourse,

iOS Extension: MyCustomShareEx.m

#import <Foundation/Foundation.h>
#import "ReactNativeShareExtension.h"
#import "RCTBundleURLProvider.h"
#import "RCTRootView.h"

@interface MyCustomShareEx : ReactNativeShareExtension
@end

@implementation MyCustomShareEx

RCT_EXPORT_MODULE();

- (UIView*) shareView {
  NSURL *jsCodeLocation;
  
  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
  
  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"MyCustomShareEx"
                                               initialProperties:nil
                                                   launchOptions:nil];
  rootView.backgroundColor = nil;
  return rootView;
}

@end

My index.ios.js:

import React from 'react'
import { AppRegistry } from 'react-native'
import Index from './src/Index'
import Share from './share.ios'

AppRegistry.registerComponent('MyProject', () => Index);
AppRegistry.registerComponent('MyCustomShareEx', () => Share);

My share.ios.js:

import React, { Component } from 'react'
import Modal from 'react-native-modalbox'
import ShareExtension from 'react-native-share-extension'

import {
  Text,
  TextInput,
  View,
  TouchableOpacity,
  Alert
} from 'react-native'

export default class Share extends Component {
  constructor(props, context) {
    super(props, context)
    this.state = {
      isOpen: true,
      type: '',
      value: ''
    }
  }

  async componentDidMount() {
    Alert.alert(null, 'holis')

    try {
      const { type, value } = await ShareExtension.data()
      this.setState({
        type,
        value
      })
    } catch(e) {
      console.log('errrr', e)
      Alert.alert(null, e)
    }
  }

  onClose() {
    ShareExtension.close()
  }

  closing = () => {
    this.setState({
      isOpen: false
    })
  }

  render() {
    return (
      <Modal backdrop={false}
             style={{ backgroundColor: 'transparent' }} position="center" isOpen={this.state.isOpen} onClosed={this.onClose}>
          <View style={{ alignItems: 'center', justifyContent:'center', flex: 1 }}>
            <View style={{ borderColor: 'green', borderWidth: 1, backgroundColor: 'white', height: 200, width: 300 }}>
              <TouchableOpacity onPress={this.closing}>
                <Text>Close</Text>
                <Text>type: { this.state.type }</Text>
                <Text>value: { this.state.value }</Text>
              </TouchableOpacity>
            </View>
          </View>
      </Modal>
    )
  }
}

@parkerdan
Copy link
Contributor

parkerdan commented Dec 11, 2016

Build your regular project, then build your ShareExtension project.
Restart X-code and React Packager
Try Again.
Check the files in the actual node_modules...See #20.
Check the installation instructions again.
Check the installation instructions again, again...

This is a very important step...

since we deleted ShareViewController.m, we need to tell the storyboard of your share extension 
where the view needs to be loaded. So click on MainInterface.storyboard and replace the class field 
from ShareViewController to MyShareEx

I just built a new project with minimal resources and things worked.

Try using a <View style={{ height:500, width:300, backgroundColor:'deeppink' }} /> as your ShareExtension content. Forget about the modal and any information you are after and see if your build is the issue...

screen shot 2016-12-11 at 8 55 29 am

@mjracca
Copy link

mjracca commented Dec 16, 2016

+1

@luisfuertes
Copy link
Author

I try to execute new proyect with basic configuration and share-extension component only.

On new project all works fine.
captura de pantalla 2016-12-19 a las 11 51 11

But now, i try to do all steps in my project, Now the extension name is the same that the example. MyShareEx.

But on my project it doesnt work. With same share.ios.js than my new project. Here pop up view donesnt appear.
captura de pantalla 2016-12-19 a las 11 53 59

@luisfuertes
Copy link
Author

luisfuertes commented Dec 23, 2016

I try to put:
NSLog(@"MYSHAREEX LOADED");
on MyShareEx.m file, and already checked if it is my MainInterface.storyboard view controller.

But on xcode console and on safari console (sharing from safari) dont show any log.

@parkerdan you know how can i continue fixing this?

EDIT: If i execute MyShareEx project on Safari, had this log, and print my NSLog:

2016-12-23 11:38:36.509 MyShareEx[2601:59767] Failed to inherit CoreMedia permissions from 2597: (null)
2016-12-23 11:38:36.543 MyShareEx[2601:59735] MYSHAREEX LOADED
2016-12-23 11:38:36.566290 MyShareEx[2601:59766] [] nw_host_stats_add_src recv too small, received 24, expected 28
2016-12-23 11:38:36.566516 MyShareEx[2601:59766] [] nw_host_stats_add_src recv too small, received 24, expected 28
2016-12-23 11:38:36.568400 MyShareEx[2601:59766] [] nw_host_stats_add_src recv too small, received 24, expected 28
2016-12-23 11:38:36.640453 MyShareEx[2601:59767] [] nw_host_stats_add_src recv too small, received 24, expected 28
2016-12-23 11:38:36.675444 MyShareEx[2601:59767] [] nw_host_stats_add_src recv too small, received 24, expected 28
2016-12-23 11:38:37.164402 MyShareEx[2601:59768] [] nw_host_stats_add_src recv too small, received 24, expected 28
2016-12-23 11:38:37.170357 MyShareEx[2601:59768] [] nw_host_stats_add_src recv too small, received 24, expected 28
2016-12-23 11:38:37.178924 MyShareEx[2601:59768] [] ____nwlog_simulate_crash_inner_block_invoke dlopen CrashReporterSupport failed
2016-12-23 11:38:37.179151 MyShareEx[2601:59768] [] __nwlog_err_simulate_crash simulate crash failed "nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available"
2016-12-23 11:38:37.180561 MyShareEx[2601:59768] [] nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available, dumping backtrace:
        [x86_64] libnetcore-856.20.4
    0   libsystem_network.dylib             0x0000000110c02682 __nw_create_backtrace_string + 123
    1   libnetwork.dylib                    0x0000000111471932 nw_socket_add_input_handler + 3100
    2   libnetwork.dylib                    0x000000011144f4f4 nw_endpoint_flow_attach_protocols + 3768
    3   libnetwork.dylib                    0x000000011144e511 nw_endpoint_flow_setup_socket + 563
    4   libnetwork.dylib                    0x000000011144d270 -[NWConcrete_nw_endpoint_flow startWithHandler:] + 2612
    5   libnetwork.dylib                    0x000000011146844d nw_endpoint_handler_path_change + 1261
    6   libnetwork.dylib                    0x0000000111467e7c nw_endpoint_handler_start + 570
    7   libnetwork.dylib                    0x000000011147fae5 nw_endpoint_resolver_start_next_child + 2240
    8   libdispatch.dylib                   0x000000011098a810 _dispatch_call_block_and_release + 12
    9   libdispatch.dylib                   0x00000001109ac12e _dispatch_client_callout + 8
    10  libdispatch.dylib                   0x0000000110991523 _dispatch_queue_serial_drain + 1018
    11  libdispatch.dylib                   0x0000000110991cf3 _dispatch_queue_invoke + 1118
    12  libdispatch.dylib                   0x0000000110993a0e _dispatch_root_queue_drain + 506
    13  libdispatch.dylib                   0x00000001109937b4 _dispatch_worker_thread3 + 113
    14  libsystem_pthread.dylib             0x0000000110d524de _pthread_wqthread + 1129
    15  libsystem_pthread.dylib             0x0000000110d50341 start_wqthread + 13
2016-12-23 11:38:37.183676 MyShareEx[2601:59768] [] __nw_connection_get_connected_socket_block_invoke 4 Connection has no connected handler
2016-12-23 11:38:37.196 [warn][tid:main][RCTEventEmitter.m:54] Sending `websocketFailed` with no listeners registered.
2016-12-23 11:38:37.236 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "BVLinearGradient" does not exist
2016-12-23 11:38:37.330 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RCTFBLikeView" does not exist
2016-12-23 11:38:37.331 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RCTFBLoginButton" does not exist
2016-12-23 11:38:37.331 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RCTFBSendButton" does not exist
2016-12-23 11:38:37.332 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RCTFBShareButton" does not exist
2016-12-23 11:38:37.333 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RNGoogleSigninButton" does not exist
2016-12-23 11:38:37.334 [error][tid:com.facebook.react.JavaScript] undefined is not an object (evaluating 'RNGoogleSignin.BUTTON_SIZE_ICON')
2016-12-23 11:38:37.337 [fatal][tid:com.facebook.react.RCTExceptionsManagerQueue] Unhandled JS Exception: undefined is not an object (evaluating 'RNGoogleSignin.BUTTON_SIZE_ICON')
2016-12-23 11:38:37.361557 MyShareEx[2601:59767] [] nw_host_stats_add_src recv too small, received 24, expected 28
2016-12-23 11:38:37.368 [error][tid:com.facebook.react.JavaScript] Module AppRegistry is not a registered callable module (calling runApplication)
2016-12-23 11:38:37.370 [fatal][tid:com.facebook.react.RCTExceptionsManagerQueue] Unhandled JS Exception: Module AppRegistry is not a registered callable module (calling runApplication)
2016-12-23 11:38:37.376519 MyShareEx[2601:59768] [] nw_host_stats_add_src recv too small, received 24, expected 28

With Capabilities, App Groups enabled in my project target and in share extension target new log when i execute MyShareEx on safari:

2016-12-23 13:10:05.861 MyShareEx[4802:45175] Failed to inherit CoreMedia permissions from 4798: (null)
2016-12-23 13:10:05.873 MyShareEx[4802:45130] MYSHAREEX LOADED
2016-12-23 13:10:06.605 [warn][tid:main][RCTEventEmitter.m:54] Sending `websocketFailed` with no listeners registered.
2016-12-23 13:10:06.671 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "BVLinearGradient" does not exist
2016-12-23 13:10:06.744 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RCTFBLikeView" does not exist
2016-12-23 13:10:06.746 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RCTFBLoginButton" does not exist
2016-12-23 13:10:06.747 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RCTFBSendButton" does not exist
2016-12-23 13:10:06.749 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RCTFBShareButton" does not exist
2016-12-23 13:10:06.752 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RNGoogleSigninButton" does not exist
2016-12-23 13:10:06.753 [error][tid:com.facebook.react.JavaScript] undefined is not an object (evaluating 'RNGoogleSignin.BUTTON_SIZE_ICON')
2016-12-23 13:10:06.757 [fatal][tid:com.facebook.react.RCTExceptionsManagerQueue] Unhandled JS Exception: undefined is not an object (evaluating 'RNGoogleSignin.BUTTON_SIZE_ICON')
2016-12-23 13:10:06.786 [error][tid:com.facebook.react.JavaScript] Module AppRegistry is not a registered callable module (calling runApplication)
2016-12-23 13:10:06.789 [fatal][tid:com.facebook.react.RCTExceptionsManagerQueue] Unhandled JS Exception: Module AppRegistry is not a registered callable module (calling runApplication)

@parkerdan
Copy link
Contributor

parkerdan commented Dec 23, 2016

@luisfuertes, you got a pink box to show...so you did something right.

If you can't get just a simple pink box on your project, then it's a configuration issue.

If you got the pink box, then tried to make your share extension more complex...obviously something went wrong with your JavaScript. If so, share you actual Javascript component/code and I will look at it and try to point out where you went wrong.

Remember this:
A Share Extension is a separate "app". This is why you need to add the static libraries in the build phases. Are you trying to include other things in your JavaScript component?

@luisfuertes
Copy link
Author

luisfuertes commented Dec 27, 2016

@parkerdan all my config:
captura de pantalla 2016-12-27 a las 10 12 58
captura de pantalla 2016-12-27 a las 10 13 59
captura de pantalla 2016-12-27 a las 10 14 22
captura de pantalla 2016-12-27 a las 10 15 01

When i add rootView.backgroundColor = [UIColor redColor]; to MyShareEx.m the result:
captura de pantalla 2016-12-27 a las 10 18 48

But dont load react view. Has a problem with AppRegistry
Simulator log:

Dec 27 10:19:44 Mobiles-Mac-mini MyShareEx[3389]: Module AppRegistry is not a registered callable module (calling runApplication)
Dec 27 10:19:44 Mobiles-Mac-mini MyShareEx[3389]: Unhandled JS Exception: Module AppRegistry is not a registered callable module (calling runApplication)

My index.ios.js file:
captura de pantalla 2016-12-27 a las 10 21 09

And share.ios.js code (is the same that other proyect where it works:

import React, { Component } from 'react'
import ShareExtension from 'react-native-share-extension'

import {
  Text,
  TextInput,
  View,
  TouchableOpacity
} from 'react-native'

export default class Share extends Component {
  constructor(props, context) {
    super(props, context)
    this.state = {
      isOpen: true,
      type: '',
      value: ''
    }
  }

  async componentDidMount() {
    try {
      const { type, value } = await ShareExtension.data()
      this.setState({
        type,
        value
      })
    } catch(e) {
      console.log('errrr', e)
    }
  }

  onClose() {
    ShareExtension.close()
  }

  closing = () => {
    this.setState({
      isOpen: false
    })
  }

  render() {
    return (
      <View style={{ height:500, width:300, backgroundColor:'deeppink' }} />
    )
  }
}

@vinicius-sabadim
Copy link

I'm facing the same error here.
I found that the error is on the other project.

AppRegistry.registerComponent('App', () => App)
AppRegistry.registerComponent('MyShareEx', () => Share)

When I comment all the import from my App component, all starts to work.

@luisfuertes
Copy link
Author

luisfuertes commented Jan 10, 2017

I try:

MyShareEx.m

#import <Foundation/Foundation.h>
#import "ReactNativeShareExtension.h"
#import "RCTBundleURLProvider.h"
#import "RCTRootView.h"

@interface MyShareEx : ReactNativeShareExtension
@end

@implementation MyShareEx

RCT_EXPORT_MODULE();

- (UIView*) shareView {
  NSURL *jsCodeLocation;

  
  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios-extension" fallbackResource:nil];
  
  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"MyShareEx"
                                               initialProperties:nil
                                                   launchOptions:nil];
  rootView.backgroundColor = nil;

  return rootView;
}

@end

And index.ios-extension.js

import React from 'react'
import { AppRegistry } from 'react-native'
import Share from './share.ios'

AppRegistry.registerComponent('MyShareEx', () => Share)

And now it works on iOS simulator, but doesn't work on real iOS device.

Log error:
Module AppRegistry is not a registered callable module (calling runApplication)

@alinz
Copy link
Owner

alinz commented Jan 10, 2017

@luisfuertes, I have no problem using this, and as far as I know the doc is pretty much describe the process. Have you looked into this section of doc? https://github.com/alinz/react-native-share-extension#test-on-device-without-dev-server

@luisfuertes
Copy link
Author

luisfuertes commented Jan 10, 2017

Yes, i have that script implemented on my code. But it doesnt work. On iOS device have the same issue. Dont show react view and log: Module AppRegistry is not a registered callable module (calling runApplication)

Im working on it, if i have some news, i will post here.

EDIT: Script must add only on extension or on main project too?

@luisfuertes
Copy link
Author

luisfuertes commented Jan 12, 2017

If i comment all index component work on iPhone device, like @vinicius-sabadim
New Index.js

import { View,	Navigator,	StyleSheet,	TouchableOpacity,	Image,	Dimensions,	BackAndroid,	Platform,	ToastAndroid,	Text,	Alert, } from 'react-native'
import React, { Component } from 'react'

export default class Index extends Component {
	render(){
		return(
			<View style={{flex: 1, backgroundColor: 'blue'}}/>
		)
	}
}

@alinz you know how can i fix it with my normal index.js?

EDIT:
It crash when i import
import {GoogleSignin, GoogleSigninButton} from 'react-native-google-signin';
for example.

I try to add libRNGoogleSignin.a to MyShareEx -> Linked Frameworks Libraris

but it cant compile with -ObjC (Other Linker Flags and add -ObjC and -lc++)

If i remove -ObjC from Other Linker Flags, share doesnt works.

@alinz
Copy link
Owner

alinz commented Jan 13, 2017

@luisfuertes can you change the workflow. Instead of login in the user in share extension, they should login in your app first and then you can access the the token from share extension. I haven't actually see any apps let's you login in share extension. They usually prompt you to log in inside app or use deep liking to open up your app.

At the moment, I'm doing exactly like that in my app. If users are not logged in, I push them back to main app for login procedure.

@luisfuertes
Copy link
Author

luisfuertes commented Jan 13, 2017

I dont use google login on extension.

You can see my extension code some post before.

The google import is in my main app. If i comment it (and others). Extension works. But if i import google login (only import, not use) on my main app. Extension doesnt works

@adrianotadao
Copy link

@luisfuertes There is something wrong with the google. We had some problem similar here and when something goes wrong, the react-native return a generic error.

  • What we did that had solved our problem:
    We added the lib, in our case was react-native-cookies on Link Binary With Libraries.
    9oa_gkw9

  • We use a lot the command react-native log-ios to see what is happening because a small error can return the error: Module AppRegistry is not a registered callable module (calling runApplication)

@luisfuertes
Copy link
Author

luisfuertes commented Jan 18, 2017

@adrianotadao thanks for answer.

I tried to add libRNGoogleSignin.a to Share target on Link Binary With Libraries List
but libRNGoogleSignin.a cant compile with ObjC on Other Linker Flags

@adrianotadao
Copy link

@luisfuertes I need to confess. React-native is almost a magic box. =l I don't know how can I help you. I'm having problems here and it's very painful

@alinz
Copy link
Owner

alinz commented Jan 20, 2017

@luisfuertes can you provide a sample project/repo so I can jump on it. I might have more clear visions and solutions once I see the problems on my computer.

@ollar
Copy link

ollar commented Feb 6, 2017

Hey guys. Any updates in this issue?

@alinz
Copy link
Owner

alinz commented Feb 6, 2017

@ollar I can't go on and investigate on this issue unless some one creates a sample project. I am using this project into couple of apps and so far no problem.

@johuder33
Copy link

johuder33 commented Feb 6, 2017

Hi, guys, @alinz awesome work, I am using react-native-share-extension, everything goes good, but I am facing a little problem, I am trying to use Alert API from react-native package, but it doesn't work, anyone has worked with that before ?

here my code :

/**
 * Created by juordergonzalezquinonez on 06-02-17.
 */
import React, { Component } from 'react'
import ShareExtension from 'react-native-share-extension'

import {
  Text,
  TextInput,
  View,
  TouchableOpacity
} from 'react-native'

export default class Share extends Component {
  constructor(props, context) {
    super(props, context)
    this.state = {
      isOpen: true,
      type: '',
      value: '',
      raw: ''
    }
  }

  async componentDidMount() {
    try {
      const data = await ShareExtension.data();
      const { type, value } = data;
      this.setState({
        type,
        value,
        raw: JSON.stringify(data)
      })
    } catch(e) {
      console.log('errrr', e)
    }
  }

  onClose() {
    Alert.alert('title', "My message to alert!!!");
    //ShareExtension.close();
  }

  closing = () => {
    this.setState({
      isOpen: false
    })
  };

  render() {
    return (
      <View style={{ flex: 1, borderColor: 'black', backgroundColor:"pink", opacity: 0.5, borderWidth: 1}}>
        <TouchableOpacity onPress={this.onClose}>
          <Text>Close</Text>
          <Text>type: { this.state.type }</Text>
          <Text>value: { this.state.value }</Text>
          <View style={{marginVertical: 20}}/>
          <Text>RAW: { this.state.raw }</Text>
        </TouchableOpacity>
      </View>
    )
  }
}

Another question that comes to my mind is, how you can use :

{View, Text, TouchableOpacity}

if you are not importing these components at the top of the file ?

Thanks.

@alinz
Copy link
Owner

alinz commented Feb 6, 2017

@johuder33 unfortunately that not possible. the reason is that, I'm instantiating share extension with Just the controller and there is no application window. Alert requires an application window. I think it is possible but at the moment I am busy with stuff but I would accept PR for anyone who wants to implement it.

Your alternative way is using react-native-modalbox to show the alert box and you can style it the way you want it. I have prototype a quick example.

import React, { Component } from 'react'
import { StyleSheet, View, Text, Alert } from 'react-native'
import Modal from 'react-native-modalbox'
import ShareExtension from 'react-native-share-extension'

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center'
  },
  alert: {
    width: 200,
    height: 100,
    backgroundColor: 'red',
    alignItems: 'center',
    justifyContent: 'center'
  }
})

export default class Share extends Component {
  constructor(props, context) {
    super(props, context)

    this.state = {
      showAlert: false,
      message: ''
    }
  }
  onClose() {
    ShareExtension.close()
  }

  showAlert(message) {
    this.setState({
      showAlert: true,
      message: message
    })
  }

  async componentDidMount() {
    const result = await ShareExtension.data()
    setTimeout(() => {
      this.showAlert(result.value)
    }, 3000)
  }

  render() {
    return (
      <Modal backdrop={false}
            style={{ backgroundColor: 'green' }} 
            position="center" 
            isOpen={true} 
            onClosed={this.onClose}>
        <View style={styles.container}>
          <Text>This is Share Extension2</Text>
        </View>
        <Modal backdrop={false}
              style={styles.alert} 
              position="center" 
              isOpen={this.state.showAlert}>
          <View style={styles.container}>
            <Text>{this.state.message}</Text>
          </View>     
        </Modal>
      </Modal>
    )
  }
}

hmmm, about your second part of your question, I don't quite get it. can you elaborate on that? if you don't import them then you can't use them unless you wrap them with another component inside another file and import the custom component into this file.

@johuder33
Copy link

@alinz I understand, I would like to help you with a PR, but I am not a Objetive-C developer, I am learning right now, because I would like to build some module for RN, now concerning about my second question, please forget about it, I don't know what I was thinking about at that moment hahaha!.

But there is a thing that I can't get it.

how can you debug your share extension ? I tried enabling remote debugging but not luck, do you know any way to debug into the share extension app ?

Thanks

@alinz
Copy link
Owner

alinz commented Feb 7, 2017

what you have to do is from top left corner of xcode,
screen shot 2017-02-07 at 9 50 26 am

select the share extension

screen shot 2017-02-07 at 9 50 40 am

and run it. once you do that you will be prompt to run it in safari.

then you would be able to debug it.

One thing though, you have to run your share extension in safari manually, it doesn't run automatically. once you do that then xcode will log and display everything for you.

cheers

@johuder33
Copy link

@alinz great, now it`s working, thanks too much.

@juhaelee
Copy link

juhaelee commented Mar 23, 2017

Hey @alinz! You said:

At the moment, I'm doing exactly like that in my app. If users are not logged in, I push them back to main app for login procedure.

Are you doing this by using React-native's Linking library? I'm trying to achieve this by doing something like this in the share extension if the user is not logged in:

const url = "myapp://"
Linking.canOpenURL(url).then(supported => {
   if (!supported) {
      console.log('can not open url')
   } else {
      Linking.openURL(url);
   }
})

Is this what you did? Doing this doesn't seem to be doing anything for me. I tried typing myapp:// in safari and it does execute the applink correctly

edit: I'm reading that this is not possible? http://stackoverflow.com/questions/31967734/open-container-app-from-share-extenion

@alinz
Copy link
Owner

alinz commented Mar 24, 2017

@juhaelee you just have to remember that in order for Linking to work user interaction must be performed. What I mean by this is user must initiate the trigger by tapping on request. When you type the url in safari and hit go, you as a user trigger the start.

what you have to do is show a message or open the dialogue to ask the user to launch the app, once the user accept then the process will work.

In other hand, you can't programatically open the any app without user approval.

@simsim0709
Copy link

@alinz
How can I share login token in ios?
I first tried this package in android. It's working very well, but no luck in ios.
I store login token in AsyncStorage, and if there is login token I send request to rest api server.
Android is very fine, but I can't get the token data from share extension in ios.
It's always null, although, in android it's working very well.

According to you,

they should login in your app first and then you can access the the token from share extension.

Do I have to try something else?

Sorry, for beginner's question.. I do not have ios knowledge.

@luisfuertes
Copy link
Author

@simsim0709 AsyncStorage isnt the same API that NSUser​Defaults, you can use this component to share token with NSUserDefaults: https://github.com/alinz/react-native-swiss-knife

@alinz
Copy link
Owner

alinz commented Mar 30, 2017

@simsim0709, as @luisfuertes mentioned, I have implemented react-native-swiss-knife to fix this issue of sharing anything between App and Share extensions. let me know how things go.

@luisfuertes
Copy link
Author

@alinz and about this bug, for clarify, if you install some component incompatible with -ObjC and -lc++ you cant use react-native-share-extension because you must add all your main project iOS librarys to the extension app

@alinz
Copy link
Owner

alinz commented Mar 31, 2017

@luisfuertes unfortunately even if I remove it, it won't be compatible anymore as of version 41 of react-native. from 41 they will add the -ObjC and lc++ by default to the build schema. here's the PR for that facebook/react-native@e0c3d56

I think it's time for open PR to those library and make them compatible with these flags.

@njt1982
Copy link
Contributor

njt1982 commented Jun 22, 2017

@adrianotadao @alinz I have raised react-native-google-signin/google-signin#251 as I am having the same issue.

2017-06-22 14:44:25.327 [error][tid:com.facebook.react.JavaScript] undefined is not an object (evaluating 'RNGoogleSignin.BUTTON_SIZE_ICON')
2017-06-22 14:44:25.328 [fatal][tid:com.facebook.react.ExceptionsManagerQueue] Unhandled JS Exception: undefined is not an object (evaluating 'RNGoogleSignin.BUTTON_SIZE_ICON')

We cannot include the Google library as it is not compatible with ObjC. Any ideas on how to progress with this problem?

@alinz
Copy link
Owner

alinz commented Jun 22, 2017

Unfortunately this is not the react-native-share-extension issue anymore. one quick advise, do not let user login with share extension. Share extension meant to be do one thing and one thing only. The user has to login into your main app and your main app share the credential with share extension.

I'm going to close this issue. Feel free to continue the discussion.

@alinz alinz closed this as completed Jun 22, 2017
@njt1982
Copy link
Contributor

njt1982 commented Jun 22, 2017

Agreed about the login - however, I am not doing that here. As with @adrianotadao earlier, the login is from the main app. TBH I am a bit lost as to why the extension is even trying to include this.

@vishim
Copy link

vishim commented Jun 29, 2017

@juhaelee - Did you find a solution for opening the app

what you have to do is show a message or open the dialogue to ask the user to launch the app, once the user accept then the process will work.

@alinz Do you have an example of how to do this?

@xuechinahb
Copy link

xuechinahb commented Jul 10, 2017

Same......
Now, I have a simple project with basic configuration. https://github.com/xuechinahb/ShareApp. react native V0.39.2. Only run on iphone. I open safari, then click share icon, nothing happened.

@alinz
Copy link
Owner

alinz commented Jul 10, 2017

@xuechinahb the link that you provided is broken. is this a private repo?

@xuechinahb
Copy link

xuechinahb commented Jul 10, 2017

@alinz try again , or go to my repos, the lastest one is it.
Moreover, according to the readme, I build a same project that named "Sample1", share extension named "MyShareEx". Everything is done. Then I compare my source code with your example code by "Beyond Compare".It seems that there is no clear difference . Your example code is ok, but my donot work.

@xuechinahb
Copy link

xuechinahb commented Jul 10, 2017

It is much strange. Sometimes it can show modal quickly, or delay long time . Sometimes Safari has no response, Safari is dead, I must kill Safari and restart it. Moreover, as mentioned above, nothing happened.
When two projects or above install react-native-share-extension, build and run with the one iphone, Safari will be no response.
When init a blank project, share extension works. But integrated into my current react-native app project, it does not work, Safari has no response.In fact, Safari is covered by a UiView.

@ncnlinh
Copy link

ncnlinh commented Aug 17, 2017

@luisfuertes @njt1982 Guys.

I found a way to hack through this. In fact, you can even skip some of the libraries in this

image linking library part of the installation and just import whatever you need for the ShareExtension to run (such as basic libraries like libReact.a, libRCTImage.a, libRCTLinking.a, libRCTNetwork.a, libRCTText.a, etc...) and therefore not importing libRNGoogleSignin.a and other culprits.

In the .m file (i.e.MyShareEx.m), instead of using @"index.ios" for jsBundleURLForBundleRoot, change to something like @"share.ios".

In your index.ios.js file, don't do AppRegistry.registerComponent() for the MyShareEx module but create a new file at your root called share.ios.js and put AppRegistry.registerComponent() there.

The reason for this is that, MyShareEx.m will load the whole index.ios.js file just for the share extension (and that's not necessary); therefore register whatever screens/functionalities on your main app, including whichever screens that have references to the Google Sign In button as well as other libraries (and that's why you will have to link the libRNGoogleSignin.a so that the Javascript side won't scream out omg, undefined is not an object (evaluating 'RNGoogleSignin.BUTTON_SIZE_ICON')

One thing that I still haven't figured out is if when the app is bundled and exported, how will RN bundle both of the js files that are needed for the main app and the share extension. I will need to try exporting the app and try it out. Anyone with more knowledge on this can enlighten me?

Hope that this will help.

@alinz
Copy link
Owner

alinz commented Aug 17, 2017

@ncnlinh that is really good and as you mentioned in the last section, unless you want to hack the bundler itself. And that is why I put the whole registration there. one way to solve this elegantly without doing too much hack is this.

you simply use require instead of import only at the boot time so you won't load unnecessary code.

as a side note: in my experience with react-native, try not to modify the internals as the next version might break your changes.

@antony-meunier
Copy link

antony-meunier commented Jun 14, 2018

@ncnlinh I did exactly the same thing, and it work great on Simulator, but doesn't load at all on real device. It there any fix out there or is this dead ?

And if I try what's in the tutorial, It show the view (with the red background) but doesn't show my react native share view.

@sujitkaulavkar123
Copy link

sujitkaulavkar123 commented May 8, 2019

Hi @alinz , I am using the react-native-share-extension in one of my project. I have integrated the package as suggested. I am able to see the UI when I am sharing the text in Android. But in iOS, I can't see the UI.
After doing some research, I found that whenever I am importing another file, it stops working. This is specifically in iOS only. Following is my code.

RCT_EXPORT_MODULE();
- (UIView*) shareView {
  NSURL *jsCodeLocation;
  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"shareIndex" fallbackResource:nil];
//
  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"EWA_Chat"
                                               initialProperties:nil
                                                   launchOptions:nil];
  rootView.backgroundColor = nil;
  // Uncomment for console output in Xcode console for release mode on device:
  // RCTSetLogThreshold(RCTLogLevelInfo - 1);
  
  return rootView;
}
@end
   import { View, AppRegistry } from 'react-native';
import React, { Component } from 'react';
import Share from './Share';   // **This line is creating issue**
export default class shareIndex extends Component {
	render() {
		return (
			<View style={{ flex: 1, backgroundColor: 'blue' }}>
                             <Share/>	// **This line is creating issue**			
			</View>
		)
	}
}
AppRegistry.registerComponent("EWA_Chat", () => shareIndex);

Now, whenever I am importing the Share file, it is not loading the view. If I comment out the Share import and then I can see the blue view.

I want to load other UI from share extension. Can you guide me how can I achieve it or point out what I am missing here.
Thanks

@pisacode
Copy link

Creating a new index file for share component fixed it for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests