2014-08-28 3 views
0

내 애플리케이션은 webview입니다. 정상적으로로드 페이지 http://staging.nhomxe.vn. 그러나 서버가 알림을 보내고 링크를 첨부했습니다. Webview에서이 링크를 엽니 다.오류 웹 뷰 ios

내 응용 프로그램 활동 정상입니다. 그런 다음 Navigation Controller를 ViewControler에 추가합니다. 서버에서 알림을 보내면 [vc.webView loadRequest : urlRequest]에서 webview 알림 오류가 발생합니다. , 응용 프로그램 자동 종료 등이 있습니다.

내 코드 :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound)]; 
UILocalNotification *localNotif = 
[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 

if (localNotif) { 
    // launched from notification 
    NSLog(@"Co notify!!!"); 
    NSString *message = [localNotif valueForKey:@"link"]; 
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    [defaults setValue:message forKey:@"LINK"]; 

} else { 
    // from the springboard 
    NSLog(@"Khong co notify!!!"); 

} 
return YES; 
} 



- (void)applicationWillEnterForeground:(UIApplication *)application 
{ 

} 
- (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 
{ 
NSLog(@"My token: %@",deviceToken); 
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
[defaults setValue:deviceToken forKey:@"TOKEN"]; 
} 

- (void) application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error 
{ 
NSLog(@"Error: %@",error); 
} 


- (void)applicationWillResignActive:(UIApplication *)application 
{ 
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 
} 

- (void)applicationDidBecomeActive:(UIApplication *)application 
{ 
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
} 

- (void)applicationWillTerminate:(UIApplication *)application 
{ 
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 
} 

- (void)application:(UIApplication*)application didReceiveRemoteNotification: 
(NSDictionary*)userInfo 
{ 
NSURL *url ; 
NSLog(@"Received notification: %@", userInfo); 
NSDictionary *data = [ userInfo objectForKey:@"aps"]; 
for(NSString *key in data) { 
    NSString *info = [data objectForKey:key]; 
    NSLog(@"thong tin nhan dc: %@ : %@", key, info); 
} 

NSString *message = [userInfo valueForKey:@"link"] ; 
//NSArray *info = [message componentsSeparatedByString:@"&@"]; 
//NSString *body = [info objectAtIndex:0]; 
//NSString *link = [info objectAtIndex:1]; 
NSLog(@"Thong tin Link: %@",message); 
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
[defaults setValue:message forKey:@"LINK"]; 
ViewController *vc = (ViewController *)self.window.rootViewController; 
if(message == NULL) 
{ 
    url = [NSURL URLWithString:@"http://staging.nhomxe.vn"]; 
}else 
{ 
    url = [NSURL URLWithString:message]; 
} 

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; 
[vc.webView loadRequest:urlRequest]; 
[vc.webView3 loadRequest:urlRequest]; 


} 

@end 

내 오류 : rootViewController가 탐색 스택을 관리하는 데 사용되는 UINavigationController을 반환

2014-08-28 14:51:59.374 NhomXe[30379:907] Thong tin Link: http://staging.nhomxe.vn/org/instance_message/conversation-detail.xhtml?post=13001628&[email protected] 
2014-08-28 14:52:14.950 NhomXe[30379:907] -[UINavigationController webView]: unrecognized selector sent to instance 0x1d5c8350 
2014-08-28 14:52:14.958 NhomXe[30379:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController webView]: unrecognized selector sent to instance 0x1d5c8350' 
*** First throw call stack: 
(0x314e22a3 0x3913e97f 0x314e5e07 0x314e4531 0x3143bf68 0xd687f 0x3353d585 0x3353dfa5 0x33f53305 0x314b7173 0x314b7117 0x314b5f99 0x31428ebd 0x31428d49 0x34fa52eb 0x3333e301 0xd6ad9 0x39575b20) 
libc++abi.dylib: terminate called throwing an exception 

답변

0

, 그는 뷰 컨트롤러의 배열로 표현된다.

예를 들어, 뷰 컨트롤러가 topViewController을 받고 시도 효율적으로 활용하려면 다음

NSLog(@"%@", navigationController.viewControllers); 

업데이트하여 UI에 :

UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController; 

ViewController *vc = (ViewController *)navigationController.topViewController; 

또한 탐색에 의해 관리하는 모든 뷰 컨트롤러의 배열을 얻을 수 있습니다 메인 스레드 :

dispatch_async(dispatch_get_main_queue(), ^{ 
    // make sure vc is a weak refernace to avoid retain cycle 
    [vc.webView loadRequest:urlRequest]; 
    [vc.webView3 loadRequest:urlRequest]; 
}); 
+0

저는 ViewController * vc = (ViewController *)를 사용합니다. self.window.rootViewCon troller.modalViewController; 내 응용 프로그램에서 오류를 알리지 않습니다. webView는 notify에서 링크를 다시로드하지 않습니다. – Takeshi

+0

웹 사이트가 초기화되었는지 확인하십시오. –

+0

내 webview가 작동하지 않습니다. 그것은 단지 curent 페이지를 보여줍니다. – Takeshi