PhoneGap中文网

 找回密码
 立即注册
查看: 12954|回复: 1
打印 上一主题 下一主题

原生页面和H5页面跳转崩溃问题

[复制链接]

3

主题

6

帖子

49

积分

新手上路

Rank: 1

积分
49
跳转到指定楼层
楼主
发表于 2016-4-18 13:55:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式


从原生页面跳转到H5页面后,在页面未加载完后返回原生页面。

原生页面 到H5的跳转是push出来的。
H5 跳转回原生页面 是写了一个插件,将H5页面pop出去。

会出现崩溃现象,检查了 代理等 均会在所继承的父类CDVViewController中移除。

报错如下:

2016-04-18 11:29:59.828 TB[6605:2578321] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x1291e55a0 of class UIView was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x129336740> (
<NSKeyValueObservance 0x12908d840: Observer: 0x1290ca140, Key path: frame, Options: <New: NO, Old: NO, Prior: NO> Context: 0x0, Property: 0x127e43230>
<NSKeyValueObservance 0x1292f41b0: Observer: 0x1290ca140, Key path: bounds, Options: <New: NO, Old: NO, Prior: NO> Context: 0x0, Property: 0x12938e080>
)'
*** First throw call stack:
(0x18164d900 0x180cbbf80 0x18164d848 0x181f8f5c0 0x180cd5ae8 0x18153142c 0x181602a20 0x181531680 0x182a40088 0x1863a8d90 0x1000d82f0 0x1810d28b8)
libc++abi.dylib: terminating with uncaught exception of type NSException




下面 是相关的插件及加载H5页面的类

插件类:
  1. #import "xzWindows.h"
  2. #import "XTBHtmlViewController.h"
  3. @implementation xzWindows
  4. #pragma mark - 从Native跳转到Html/ 从Html跳转到Native

  5. -(void)nativeJumpToHtml:(CDVInvokedUrlCommand *)command
  6. {
  7.     /*
  8.      NSString* _callbackId; 回调id
  9.      NSString* _className;  类名
  10.      NSString* _methodName; 方法名
  11.      NSArray* _arguments;  参数
  12.      */
  13.    
  14.     [[NSNotificationCenter defaultCenter] postNotificationName:@"StartPageWithHtml" object:nil userInfo:@{@"startPage":command.arguments[0]}];
  15.     DLog(@"???");
  16.     CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
  17.     [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
  18. }
  19. - (void)close:(CDVInvokedUrlCommand*)command;
  20. {
  21.     [[NSNotificationCenter defaultCenter] postNotificationName:@"HtmlBackToNative" object:nil userInfo:nil];
  22.     CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
  23.     [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
  24. }

  25. @end
复制代码


加载H5页面的类,已继承 CDVViewController
XTBMessageNoticeViewController.h


  1. //
  2. //  XTBMessageNoticeViewController.h
  3. //  TB
  4. //
  5. //  Created by hanyutong on 16/3/4.
  6. //
  7. //

  8. #import <cordova/CDVViewController.h>
  9. #import <Cordova/CDVCommandDelegateImpl.h>
  10. #import <Cordova/CDVCommandQueue.h>


  11. @interface XTBHtmlViewController : CDVViewController

  12. @end


  13. @interface HtmlCommandDelegate : CDVCommandDelegateImpl

  14. @end

  15. @interface HtmlCommandQueue : CDVCommandQueue


  16. @end
复制代码





XTBMessageNoticeViewController.m
  1. //
  2. //  XTBMessageNoticeViewController.m
  3. //  TB
  4. //
  5. //  Created by hanyutong on 16/3/4.
  6. //
  7. //

  8. #import "XTBHtmlViewController.h"

  9. @interface XTBHtmlViewController ()

  10. @end

  11. @implementation XTBHtmlViewController
  12. - (id)init
  13. {
  14.     self = [super init];
  15.     if (self)
  16.     {
  17.         // Uncomment to override the CDVCommandDelegateImpl used
  18.         // _commandDelegate = [[MainCommandDelegate alloc] initWithViewController:self];
  19.         // Uncomment to override the CDVCommandQueue used
  20.         // _commandQueue = [[MainCommandQueue alloc] initWithViewController:self];
  21.     }
  22.     return self;
  23. }

  24. - (void)viewDidLoad
  25. {
  26.     [super viewDidLoad];

  27.     [[NSNotificationCenter  defaultCenter] addObserver:self selector:@selector(StartPageWithHtml:) name:@"StartPageWithHtml" object:nil];
  28.     [[NSNotificationCenter  defaultCenter] addObserver:self selector:@selector(backAction:) name:@"HtmlBackToNative" object:nil];
  29. }

  30. - (void)viewWillAppear:(BOOL)animated
  31. {
  32.     [super viewWillAppear:animated];
  33.     [self.navigationController setNavigationBarHidden:YES animated:YES];

  34. }

  35. - (void)viewWillDisappear:(BOOL)animated
  36. {
  37.     [super viewWillDisappear:animated];
  38.     [self.navigationController setNavigationBarHidden:NO animated:YES];
  39. }

  40. - (void)didReceiveMemoryWarning
  41. {
  42.     [super didReceiveMemoryWarning];

  43.     // Dispose of any resources that can be recreated.
  44. }

  45. - (void)StartPageWithHtml:(NSNotification*)info
  46. {
  47.      self.startPage = [info.userInfo objectForKey:@"startPage"];
  48.     DLog(@"self.startPage  %@",self.startPage);
  49. }

  50. - (void)backAction:(NSNotification*)info
  51. {
  52.     [self.navigationController popViewControllerAnimated:YES];
  53. }


  54. #pragma mark UIWebDelegate implementation
  55. - (void)webViewDidFinishLoad:(UIWebView*)theWebView
  56. {
  57.     // Black base color for background matches the native apps
  58.     theWebView.backgroundColor = [UIColor blackColor];
  59.    
  60.     return [super webViewDidFinishLoad:theWebView];
  61. }




  62. @end



  63. @implementation HtmlCommandDelegate

  64. /* To override the methods, uncomment the line in the init function(s)
  65. in MainViewController.m
  66. */

  67. #pragma mark CDVCommandDelegate implementation

  68. - (id)getCommandInstance:(NSString*)className
  69. {
  70.     return [super getCommandInstance:className];
  71. }

  72. - (NSString*)pathForResource:(NSString*)resourcepath
  73. {
  74.     return [super pathForResource:resourcepath];
  75. }
  76. @end



  77. @implementation HtmlCommandQueue

  78. /* To override, uncomment the line in the init function(s)
  79. in MainViewController.m
  80. */
  81. - (BOOL)execute:(CDVInvokedUrlCommand*)command
  82. {
  83.     return [super execute:command];
  84. }

  85. @end
复制代码






回复

使用道具 举报

11

主题

529

帖子

1418

积分

金牌会员

Rank: 6Rank: 6

积分
1418
沙发
发表于 2016-4-19 09:51:29 | 只看该作者
找个懂原生的问问,不懂原生
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

ionic4视频教程

Archiver|手机版|小黑屋| PhoneGap中文网 ( 京ICP备13027796号-1 )  

GMT+8, 2024-4-25 17:38 , Processed in 0.035868 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表