【问题标题】:Warning: Attempt to present UINavigationController on UIViewController which is already presenting警告:尝试在已经呈现的 UIViewController 上呈现 UINavigationController
【发布时间】:2017-06-16 15:18:18
【问题描述】:

我有一个关于 react native 的模块,并在这个问题的标题中抛出错误。这是模块的代码,我不知道swift或objective-c,所以我需要你像“swift for idiots”一样解释我

#import "CheckoutMercadoPagoModule.h"
#import "AppDelegate.h"

@import MercadoPagoSDK;

@implementation CheckoutMercadoPagoModule

RCT_EXPORT_MODULE()

- (dispatch_queue_t)methodQueue
{
    return dispatch_get_main_queue();
}

RCT_EXPORT_METHOD(startCheckout:(NSString *)publicKey:(NSString *)prefId:(RCTPromiseResolveBlock)resolve:(RCTPromiseRejectBlock)reject) {

    [MercadoPagoContext setPublicKey: publicKey];
    [MercadoPagoContext setSiteID:@"MLA"];

    UINavigationController *checkoutFlow = [MPFlowBuilder startCheckoutViewController:prefId callback:^(Payment *payment) {
        NSDictionary *dictionary = @{@"id": payment._id, @"status": payment.status};
        resolve(dictionary);
    } callbackCancel:nil];

    AppDelegate *share = (AppDelegate *)[UIApplication sharedApplication].delegate;
    UINavigationController *nav = (UINavigationController *) share.window.rootViewController;
    [nav presentViewController:checkoutFlow animated:YES completion:^{}];
}

@end

【问题讨论】:

  • 这是 React 生成的代码?
  • 不,这是一些在 MercadoPago SDK 和 React Native 之间架起桥梁的人编写的代码
  • 是的,但这并不能解决我的问题,谢谢

标签: ios objective-c swift xcode react-native


【解决方案1】:

尝试在 Window 本身而不是 rootviewcontroller 上呈现

  [share.window presentViewController:checkoutFlow animated:YES completion:^{}];

}

【讨论】:

  • 你能帮我写一个例子吗,我不知道 swift,几个小时后我要开会
  • 你贴的代码是Objective-C,你还想要and in swift吗?
  • 不,抱歉,我觉得很快,我只是想让它工作 T.T
  • CheckoutMercadoPagoModule.m:28:12:在“AppDelegate *”类型的对象上找不到属性“keywindow”;你是说“窗户”吗?
  • 改成window试试
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-07
  • 2014-10-02
  • 1970-01-01
  • 2016-10-20
  • 2016-11-29
  • 1970-01-01
相关资源
最近更新 更多