原生页面和H5页面跳转崩溃问题
从原生页面跳转到H5页面后,在页面未加载完后返回原生页面。
原生页面 到H5的跳转是push出来的。
H5 跳转回原生页面 是写了一个插件,将H5页面pop出去。
会出现崩溃现象,检查了 代理等 均会在所继承的父类CDVViewController中移除。
报错如下:
2016-04-18 11:29:59.828 TB *** 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页面的类
插件类:
#import "xzWindows.h"
#import "XTBHtmlViewController.h"
@implementation xzWindows
#pragma mark - 从Native跳转到Html/ 从Html跳转到Native
-(void)nativeJumpToHtml:(CDVInvokedUrlCommand *)command
{
/*
NSString* _callbackId; 回调id
NSString* _className;类名
NSString* _methodName; 方法名
NSArray* _arguments;参数
*/
[ postNotificationName:@"StartPageWithHtml" object:nil userInfo:@{@"startPage":command.arguments}];
DLog(@"???");
CDVPluginResult* pluginResult = ;
;
}
- (void)close:(CDVInvokedUrlCommand*)command;
{
[ postNotificationName:@"HtmlBackToNative" object:nil userInfo:nil];
CDVPluginResult* pluginResult = ;
;
}
@end
加载H5页面的类,已继承 CDVViewController
XTBMessageNoticeViewController.h
//
//XTBMessageNoticeViewController.h
//TB
//
//Created by hanyutong on 16/3/4.
//
//
#import <Cordova/CDVViewController.h>
#import <Cordova/CDVCommandDelegateImpl.h>
#import <Cordova/CDVCommandQueue.h>
@interface XTBHtmlViewController : CDVViewController
@end
@interface HtmlCommandDelegate : CDVCommandDelegateImpl
@end
@interface HtmlCommandQueue : CDVCommandQueue
@end
XTBMessageNoticeViewController.m
//
//XTBMessageNoticeViewController.m
//TB
//
//Created by hanyutong on 16/3/4.
//
//
#import "XTBHtmlViewController.h"
@interface XTBHtmlViewController ()
@end
@implementation XTBHtmlViewController
- (id)init
{
self = ;
if (self)
{
// Uncomment to override the CDVCommandDelegateImpl used
// _commandDelegate = [ initWithViewController:self];
// Uncomment to override the CDVCommandQueue used
// _commandQueue = [ initWithViewController:self];
}
return self;
}
- (void)viewDidLoad
{
;
[ addObserver:self selector:@selector(StartPageWithHtml:) name:@"StartPageWithHtml" object:nil];
[ addObserver:self selector:@selector(backAction:) name:@"HtmlBackToNative" object:nil];
}
- (void)viewWillAppear:(BOOL)animated
{
;
;
}
- (void)viewWillDisappear:(BOOL)animated
{
;
;
}
- (void)didReceiveMemoryWarning
{
;
// Dispose of any resources that can be recreated.
}
- (void)StartPageWithHtml:(NSNotification*)info
{
self.startPage = ;
DLog(@"self.startPage%@",self.startPage);
}
- (void)backAction:(NSNotification*)info
{
;
}
#pragma mark UIWebDelegate implementation
- (void)webViewDidFinishLoad:(UIWebView*)theWebView
{
// Black base color for background matches the native apps
theWebView.backgroundColor = ;
return ;
}
@end
@implementation HtmlCommandDelegate
/* To override the methods, uncomment the line in the init function(s)
in MainViewController.m
*/
#pragma mark CDVCommandDelegate implementation
- (id)getCommandInstance:(NSString*)className
{
return ;
}
- (NSString*)pathForResource:(NSString*)resourcepath
{
return ;
}
@end
@implementation HtmlCommandQueue
/* To override, uncomment the line in the init function(s)
in MainViewController.m
*/
- (BOOL)execute:(CDVInvokedUrlCommand*)command
{
return ;
}
@end
找个懂原生的问问,不懂原生{:2_25:}{:4_87:}
页:
[1]