Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all 16555 articles
Browse latest View live

react native crash when tapping navigation button too fast

$
0
0

I used react navigation 4.0.10 and it's little bit complicated app with nested navigator. Currently it's performing relatively well except that When I try to navigate it very fast, it will crash. The error message is

TypeError: undefined is not an object (evaluating 'navigation.state')

The structure is

-bottomTapNavigator(Home, Scan; Scan is a stackNavigator)
 --HomeScreen
 --ScanNavigator(stackNavigator, parent for ScanScreen and JourneyNavigator[tabNavigator])
   ---ScanScreen(Real page, initial screen of ScanNavigator, having buttons to navigate(HomeScreen) and navigate(JourneyNavigator))
   ---JourneyNavigator(TabNavigator, including ScreenTest1 and ScreenTest2; having header with back button navigate(ScanScreen) for both ScreenTest1 and ScreenTest2;)
      ---ScreenTest1(Real page)
      ---ScreenTest2(Real page, does not matter in this case)

what I do is tap ScanNavigator[ScanScreen]->ScreenTest1->ScanScreen(tap navigation button quickly here)->HomeScreen

In such case, the app will crash. If i do it with normal pace then it's fine.

Any help or direction is welcome.

EDIT

I'm 100 percent certain it's something to do with resetOnBlur setting. When it set to false, the issue gone. Question2: is it norm practice to set restOnBlur true or false ?


Branch based deployment in Microsoft Appcenter

$
0
0

I need to deploy apps to app store for each branch. I have DEV, PROD, Staging and UAT environments. Each has a separate branch. What i need to build and deploy each branch to separate app in app store.

The problem is I can only add a single app in app store connect. If i try to add again, it says 'already connected'.

Anyone knows any solution for branch based deployment to store?? I couldn't find any articles mentioning these kind of scenarios.

Scenario

Single Repo

Dev Branch ----> Dev_App

Staging branch ----> Staging_App

I have separate apps in app store for each environment.

Why is my Swfit native ui component not receiving props from React Native?

$
0
0

I'm trying to bridge my swift UI view to react-native. The component is being passed to RN correctly and mounts but I am unable to receive any props that I pass. I'm using react-native@0.59.10. I've found the documentation to be patchy and various other resources online have different methods that I've tried to no avail so any help is greatly appreciated.

RNGallery360-Bridging-Header.h

#ifndef RNGallery360_Bridging_Header_h
#define RNGallery360_Bridging_Header_h

    #import <React/RCTBridgeModule.h>
    #import <React/RCTViewManager.h>

#endif

RNGallery360.m

#import <React/RCTViewManager.h>

@interface RCT_EXTERN_MODULE(Gallery360ViewManager, RCTViewManager)
    RCT_EXPORT_VIEW_PROPERTY(width, NSInteger)
    RCT_EXPORT_VIEW_PROPERTY(height, NSInteger)
@end

Gallery360ViewManager.swift

import Foundation

@objc(Gallery360ViewManager)
class Gallery360ViewManager: RCTViewManager {
  @objc var width : NSInteger = 0
  @objc var height : NSInteger = 0

  override func view() -> UIView! {
    print("I am the width & height", width, height) // this consistently returns 0, 0
    return Gallery360(width: width, height: height)
  }

  override static func requiresMainQueueSetup() -> Bool {
    return true
  }
}

Gallery360.swift

import Foundation

@objc(Gallery360)
class Gallery360 : UIView  {
    @objc
    public convenience init(width:NSInteger, height:NSInteger) {
        self.init(frame:CGRect(x: 0, y: 0, width: width, height: height))
    }
}

Allow user to change app notification sound

$
0
0

I have an app that uses Firebase Messaging to send notifications, and I have a set of sounds added to my xcode project resources, to play on the device.

I send the notification to users subscribed to specific topics, from my server like this:

"apns": {
    "headers": {
        "apns-priority": "10",
    },
    "payload": {
        "aps": {
            "alert": {
                "title": titleMessage,
                "body": bodyMessage,
            },
            "sound": 'alert.wav',
        },
    },
}

Now the sound "alert.wav" plays fine on the device, when the notification is received.

What I want to do is inside my app: I want to allow users to change the notification sound, from different sets of sounds.

Example: Option to play sound from: set 1, or set 2. and I would have them in my app as seperate folders with the same file names.

Is this possible in iOS? and how can I achieve it in react native?

iOS React Native App/ Build Succeeded but App not getting open in iOS device/ Simulator

$
0
0

iOS App is build successfully but App is not getting open in the Simulator or device.

Getting chmod error for the app path.

Error:

info ** BUILD SUCCEEDED **

info Installing <PATH TO APP>.app
An error was encountered processing the command (domain=IXUserPresentableErrorDomain, code=1):
This app could not be installed at this time.
Could not install at this time.
Failed to chmod /Users/surabhiagrawal/Library/Developer/CoreSimulator/Devices/7A54A41E-006C-4B29-B33A-BE956F715255/data/Bundle/Application/0A68FDA4-1D57-49BB-8377-7BA5AC9BBB46/<AppName> : No such file or directory
Underlying error (domain=MIInstallerErrorDomain, code=4):
    Failed to chmod /Users/surabhiagrawal/Library/Developer/CoreSimulator/Devices/7A54A41E-006C-4B29-B33A-BE956F715255/data/Bundle/Application/0A68FDA4-1D57-49BB-8377-7BA5AC9BBB46/<AppName>.app/<AppName> : No such file or directory
info Launching <Package Name>
com.goshopmatic.ShopmaticGoApp: -1
An error was encountered processing the command (domain=FBSOpenApplicationServiceErrorDomain, code=1):
The request to open "App Package name" failed.
The request was denied by service delegate (SBMainWorkspace) for reason: NotFound ("Application <App_Path_Name> is unknown to FrontBoard").
Underlying error (domain=FBSOpenApplicationErrorDomain, code=4):
    The operation couldn’t be completed. Application "App package name" is unknown to FrontBoard.
    Application "App package name" is unknown to FrontBoard.

Network connection was lost during `application:openURL:options`

$
0
0

We are using deep links to complete verification for an app we're working on. Said deep links cause the app delegate method:

- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{

To be called. This app is using React Native, using the in-build Linking API. Some of the time making a network request when we get the Linking callback works, but sometimes we get a networking error:

Task <D47D1F90-E2D1-4AB7-8706-8737B68CC5E8>.<180> finished with error [-1005] Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={_kCFStreamErrorCodeKey=53, NSUnderlyingError=0x283352ac0 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={NSErrorPeerAddressKey=<CFData 0x281ed9130 [0x1e9babcb0]>{length = 16, capacity = 16, bytes = 0x100201bb34d2847e0000000000000000}, _kCFStreamErrorCodeKey=53, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <D47D1F90-E2D1-4AB7-8706-8737B68CC5E8>.<180>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <D47D1F90-E2D1-4AB7-8706-8737B68CC5E8>.<180>"

I've had a pretty extensive google and it seems to be suggested that this can be caused when a network request is made in the background, however Apple quite clearly state in the docs for this method:

If a URL arrives while your app is suspended or running in the background, the system moves your app to the foreground prior to calling this method.

Is there something we shouldn't be doing here? Has anyone else seen similar issues?

Update

It seems this works fine the first time the link is opened after app-launch, but if you open it a second time or 3rd or 4th we get this error. Nothing seems to be called in a different order, so it's very confusing why we'd see this sort of pattern!

Bridging Swift class to React Native after Swift 4.2 upgrade

$
0
0

In Swift 3.0, I have the following Swift class

import Foundation

@objc(NetworkManager)
class NetworkManager: NSObject {


  init(...) {
    ...
  }


  deinit {
    ...
  }

  func isConnected(resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
    ...
  }
}

And the following bridge:

#import <Foundation/Foundation.h>

#import <React/RCTBridgeModule.h>

@interface RCT_EXTERN_MODULE(NetworkManager, NSObject)
  _RCT_EXTERN_REMAP_METHOD(isConnected, isConnectedWithResolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject, NO)
@end

After upgrading to Swift 4.2, this begins to fail with isConnnectedWithResolver:rejecter is not a recognized Objective-C method.

After looking around and finding this question: Got "is not a recognized Objective-C method" when bridging Swift to React-Native, and this code sample: https://github.com/bigali/StringToHash/blob/master/ios/StringToHash/StringToHash.m

I've changed this to:

import Foundation

@objc(NetworkManager)
class NetworkManager: NSObject {


  init(...) {
    ...
  }


  deinit {
    ...
  }

  func isConnected(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
    ...
  }
}

and:

   #import <Foundation/Foundation.h>
   #import <React/RCTBridgeModule.h>

@interface RCT_EXTERN_MODULE(NetworkManager, NSObject)
  _RCT_EXTERN_REMAP_METHOD(isConnected, isConnected:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject, NO)
@end

Which only changes the function name in the error message to:

isConnnectedWithResolver:rejecter is not a recognized Objective-C method.

Whats causinng this problem? Why is the solution outlined in the other questionn not working? And how do I fix this problem?

Web scraping on react native iOS app using recurring background service

$
0
0

How do you get a background service running a web view in iOS using react- native?

I need to gather user history from myactivity.google.com on iOS using a React Native app.

I am able to do this on Android by loading the webpage in the background and scrape the data, can this be done in iOS too?


Is is possible on iPad OS to detect if the keyboard is in floating mode?

$
0
0

We're running into a specific bug on iOS/iPadOS which seems to be triggered when the iPad is showing the floating (iphone-like) keyboard on screen (instead of the anchored one)

Our issue is specific to React Native and the KeyboardAvoidingView component. When the component renders and the keyboard is floating, the KeyboardAvoidingView completely mis-calculated the height required for the keyboard and hides about 95% of the screen height instead.

The KeyboardAvoidingView itself doesn't seem to have a way to detect whether or not the floating keyboard is on.

Is there a particular API that can be tapped into to detect this keyboard mode so we can turn off the KeyboardAvoidingView for it?

The Keyboard events (keyboardWillShow, keyboardDidShow, etc) don't seem to return any specific clues.

How to add custom action button in React Native(IOS) push notification

$
0
0

Currently, I am using this package:

react-native-ios-notification-actions

But this package is only for IOS. But I need to implement an action button in both android and IOS. So is there any other way in firebase or other library support for it. I already face many issues in the package from the IOS side.

react-native How to open local file url using Linking?

$
0
0

I'm using the following code to download a file (can be a PDF or a DOC) and then opening it using Linking.

const { dirs } = RNFetchBlob.fs;
let config = {
    fileCache : true,
    appendExt : extension,
    addAndroidDownloads : {
        useDownloadManager : false,
        notification : false,
        title : 'File',
        description : 'A file.',
        path: `${dirs.DownloadDir}/file.${extension}`,
    },
};
RNFetchBlob.config(config)
    .fetch(
        method,
        remoteUrl,
        APIHelpers.getDefaultHeaders()
    )
    .then((res) => {
        let status = res.info().status;
        if (status == 200) {
            Linking.canOpenURL(res.path())
                .then((supported) => {
                    if (!supported) {
                        alert('Can\'t handle url: ' + res.path());
                    } else {
                        Linking.openURL(res.path())
                            .catch((err) => alert('An error occurred while opening the file. ' + err));
                    }
                })
                .catch((err) => alert('The file cannot be opened. ' + err));
        } else {
            alert('File was not found.')
        }
    })
    .catch((errorMessage, statusCode) => {
        alert('There was some error while downloading the file. ' + errorMessage);
    });

However, I'm getting the following error:

An error occurred while opening the file. Error: Unable to open URL:file:///Users/abhishekpokhriyal/Library/Developer/CoreSimulator/Devices/3E2A9C16-0222-40A6-8C1C-EC174B6EE9E8/data/Containers/Data/Application/A37B9D69-583D-4DC8-94B2-0F4AF8272310/Documents/RNFetchBlob_tmp/RNFetchBlobTmp_o259xexg7axbwq3fh6f4.pdf

I need to implement the solution for both iOS and Android.

How to add Notification Service Extension for Firebase?

$
0
0

I am trying to follow the guide here: https://firebase.google.com/docs/cloud-messaging/ios/send-image

I went to New > Target > Notification Service Extension (embedded this new target into the original target) and pasted in NotificationService.m:

@interface NotificationService ()

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;

@end

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
    self.contentHandler = contentHandler;
    self.bestAttemptContent = [request.content mutableCopy];

    // Modify the notification content here...
    self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title];

    // Call FIRMessaging extension helper API.
    [[FIRMessaging extensionHelper] populateNotificationContent:self.bestAttemptContent
                                             withContentHandler:contentHandler];

    self.contentHandler(self.bestAttemptContent);
}

- (void)serviceExtensionTimeWillExpire {
    // Called just before the extension will be terminated by the system.
    // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
    self.contentHandler(self.bestAttemptContent);
}

@end

I am now getting Use of undeclared identifier 'FIRMessaging' in NotificationService.m.

In NotificationService.m I tried to import similarly to my original target's AppDelegate.m where FIRMessaging is available and working with no issues:

#import "NotificationService.h"
#import <Firebase.h>
#import "RNFirebaseNotifications.h"
#import "RNFirebaseMessaging.h"
...

Then I get 'Firebase.h' file not found. I am confused because it seems to work in the original target, and this notification service extension is embedded in that target. I have tried messing with Header Search Paths and Framework Search Paths without much luck. What am I doing wrong?

application crashed when open camera

$
0
0

I'm using https://github.com/ivpusic/react-native-image-crop-picker in my app, when camera opened I can take the picture but when I want to choose it the app crashes and sometimes it's crashed once the camera is opened, but it works when I use debugging mode instead on android works very well in the all cases.

when I run the project from xcode works fine but not with react-native run-ios --device "myDeviceName"

also with higher version ios like 13 it works well

  • react-native-image-crop-picker ^0.23.1
  • react-native v0.59.0
  • Ios 9.3.6

Component when I call open camera:

ImagePicker.openCamera({
          cropping: true,
          width: 500,
          height: 500,
          includeExif: true,
          includeBase64: true,
          mediaType:"photo"
        })
          .then(image => {
            this.setState({
              cameraOpened: false
            });
            this.props.navigation.navigate("Preview", {
              picture: image,
              type: this.type,
              state: this.props.navigation.state,
              userId: this.userId
            });
          })
          .catch(e => {
            console.log(e);
            this.setState({
              cameraOpened: false
            });
            this.props.navigation.goBack();
          });
      }

Preview.js:

ImageEditor.cropImage(
          this.picture.path,
          {
            offset: { x: 0, y: 0 },
            size: { width: 500, height: 500 },
            displaySize: { width: 500, height: 500 }
          },
          res => {
            // Change it to res
            this._uploadPicture(this.picture.path, response => {
              if (response.status == 200) {
                this.props.savePicture(this.picture);
                this.setState(
                  {
                    loading: false
                  },
                  () => {
                    this.navigation.goBack(key);
                  }
                );
              } else {
                alert(response);
              }
            });
          },
          err => {
            this.setState({
              loading: false
            });
            alert(err);
          }
        );

Any idea ? Thank you

Swift bridging header not exporting React Native types

$
0
0

I'm trying to create a native (iOS) module for a React Native app using Swift. I want to expose a method on the module that returns a promise, using functions of type RCTPromiseResolveBlock and RCTPromiseRejectBlock, both of which are declared in React Native's RCTBridgeModule.h header. However, my build fails with the message "Use of undeclared type..." for both of these types.

I had already created a bridging header (automatically using Xcode) for another purpose, so I believe importing React/RCTBridgeModule.h is all that I'd need to supply the types mentioned above. Presumably I've misconfigured something, as this doesn't fix the issue. I've tried setting up a fresh project and everything works as expected there, but I can't seem to find a difference that would cause my project's build to fail.

Some relevant configuration details:

  • Bridging header named <ProjectName>-Bridging-Header.h and stored in my source directory. I moved it around to confirm that Xcode is finding it (the build fails differently when it's not in the right place).
  • The contents of the bridging header is simply: #import <React/RCTBridgeModule.h>
  • In my project build settings:
    • <ProjectName>-Bridging-Header.h is configured as the "Objective-C Bridging Header"
    • "Install Objective-C Compatibility Header" is set to "Yes"
    • "Precompile Bridging Header" is set to "Yes"
  • When I type alias the missing types the project builds and runs as expected
  • I have some third-party Swift libraries installed (one using react-native link and one using a Git submodule)
  • I've tried cleaning the build folder, reinstalling node_modules and deleting Xcode derived data, all to no effect.

Is my project misconfigured or have I otherwise missed something important?

React native - process the current camera image without triggering the shutter

$
0
0

is it possible to process the current camera image without the user triggering the shutter using react native?

Thank you!


React Native TextInput rendering text too high on iOS, cutting off the tops of some characters

$
0
0

I have a simple TextInput in my react native app. Here is the relevant code:

<View style={styles.AmountWrapper}>
    <TextInput
        multiline={true}
        placeholder="$0"
        placeholderTextColor={colors.black38}
        style={styles.NumberInput}
        keyboardType={"numeric"}
    />
</View>

let styles = StyleSheet.create({
    AmountWrapper: {
        flexDirection: "column",
        flex: 1,
        alignItems: "center",
        justifyContent: "center",
        backgroundColor: colors.white
    },
    NumberInput: {
        flexDirection: "row",
        alignItems: "center",
        flex: 0,
        fontFamily: styleHelper.fontFamily("medium"),
        fontSize: 48,
        paddingHorizontal: 16,
        paddingTop: 0,
        paddingBottom: 0,
        color: colors.blue,
        textAlign: "center",
        borderWidth: 0,
        textAlignVertical: "center"
    },
});

I am emulating on both Android Studio Pixel 3 with Android 9.0, and with Xcode's simulator, simulating iOS 12.4 iPhone X.

On Android, this is rendering exactly how I want it:

Android rendering properly

The issue is with iOS. It's rendering the text far too high up, cutting off the top of the dollar sign, and a few pixels of the number. It does this both with the placeholder, and when the user enters text:

iOS rendering improperly

I have tried changing margin, padding, textAlign, lineHeight, flexDirection, alignItems, and justifyContent. I have also tried multiline={false} within the TextInput.

How do I get iOS rendering the text further down and displaying properly within the TextInput?

The action buttons in iOS notification are not coming after navigation to the other screen using react navigation

$
0
0

Heyy I am using react native(0.52) for building my iOS app.I am using react navigation library(1.0.0) for navigating around different screens.I am trying to get action buttons for my iOS notifications.I have successfully registered the categories for iOS notification in my native method of appdelegate.m .But when I get my first notification with action buttons I am using react navigation to redirect to other screens according to the action buttons user has clicked.After successfully redirecting to the other screen when I again get the notification the action buttons are not coming.Is this the problem of react navigation library?.Does anyone know workaround?

React Native Expo: RTL not working on actual Device but works fine on iOS Simulator

$
0
0

I am using I18NText library for RTL & translation. I see different results on Expo app running on a device vs an iOS simulator running on my machine. Both simulator and Expo app have device language has Arabic(RTL).

I see the "< Back" button on the header as expected(on top right side) on the simulator but the Expo app does not flip the position of back button(still shows on top left).

Same goes for Tab bar icons sequence. It shows in correct order in the RTL simulator but not on the device.

Huge app size of iOS build in react native

$
0
0

how to reduce app size in react-native ios. In android i'll include the "armeabi-v7a", "x86" into build gradle file, its working fine. for ios?

React-native : 0.57.7

How to zoom out React-Native map

$
0
0

Hi I just begin to use react-native. How to restricted from zooming out and in too much on react-native map? Is there a var that i can set to to limit the zooming?

Viewing all 16555 articles
Browse latest View live