2013-01-25 27 views
0

我在一個應用程序的工作是基於ChattAr-iOS項目從QuickBlox中,他們有一個UIWebViewController由於我不能與其他應用進行溝通,每次我試圖打開Waze應用形成我的應用程序進行通信使用以下代碼:與其他iOS應用

- (void) navigateToLatitude:(double)latitude 
       longitude:(double)longitude 
{ 
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"waze://"]]) { 
    //Waze is installed. Launch Waze and start navigation 
    NSString *urlStr = [NSString stringWithFormat:@"waze://?ll=%f,%f&navigate=yes", latitude, longitude]; 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]]; 
} else { 
    //Waze is not installed. Launch AppStore to install Waze app 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/us/app/id323229106"]]; 
    } 
} 

它導航到那個UIWebView。該項目中有一類ChatARApplication,可能是導致問題的原因。

ChattARApplication.h

#import <UIKit/UIKit.h> 

@interface ChattARApplication : UIApplication 

@end 

ChattARApplication.m

#import "ChattARApplication.h" 
#import "WebViewController.h" 
#import "AppDelegate.h" 

@implementation ChattARApplication 

-(BOOL)openURL:(NSURL *)url{ 
    UITabBarController *tabBarControlelr = ((AppDelegate *)self.delegate).tabBarController; 
if(tabBarControlelr.selectedIndex != 1){ 
    return [super openURL:url]; 
    } 

    // handle chat messages' links 
    WebViewController *webViewControleler = [[WebViewController alloc] init]; 
    webViewControleler.urlAdress = [url absoluteString]; 
    webViewControleler.webView.scalesPageToFit = YES; 
    UINavigationController *chatViewController = [tabBarControlelr.viewControllers objectAtIndex:1]; 
    [chatViewController pushViewController:webViewControleler animated:YES]; 
    [webViewControleler autorelease]; 

    return NO; 
} 

@end 

回答

1

解決

這個代碼稍稍安心的伎倆

if ([[url scheme] isEqualToString:@"waze"]) { 
    return [super openURL:url]; 
} 

-(BOOL)openURL:(NSURL *)url

問題
0

的main.m

int main(int argc, char *argv[]){ 
    @autoreleasepool { 
     return UIApplicationMain(argc, argv, NSStringFromClass([ChattARApplication class]), NSStringFromClass([AppDelegate class])); 
    } 
} 

我認爲這是問題所在。要保持應用程序設置,你米唉把一些代碼在-(BOOL)openURL:(NSURL *)url;

公司希望它可以幫助你~~

+0

謝謝史蒂文。我已根據您的建議添加了答案。 –