2017-01-20 12 views
1

私は、Webビューからデータを取得するためにページのWebビューをロードするアプリケーションを作成しています。 iOSアプリケーションのローカルSQLiteデータベースにデータを送信します。現在の問題は、Webビューでデータが通知されても、のWeb View Delegateでデータを受け取ることができません。つまり、Web View Delegate領域のログに印刷しようとしましたが、表示します。iOSのウェブビューでサーバーからデータを呼び出すことができません 'ios:' concat(データ)

URL : http://35.161.118.210/list/12345.html 

サーバーページのデータ

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> 

<script> 
    setInterval(function(){ 
     var data = "Notice 1:::Notice 2:::Notice 3:::Notice 4:::Notice 5:::Notice 6"; 
      if(data.length > 5){ 
      window.location = 'ios:'.concat(data); 
      $('#notice').text("Unread Notice"); 
      alert(data); 
      } 
     }, 5000); 
</script> 

のWebViewロード

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-64)]; 
    NSString *htmlFile = [[NSUserDefaults standardUserDefaults] objectForKey:USER_CODE]; 
    NSURL *url = [NSURL URLWithString:htmlFile]; 
    [webView loadRequest:[NSURLRequest requestWithURL:url]]; 
    [self.view addSubview:webView]; 
} 

のWebビューの委任

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { 
    NSString *strResponse = [[request URL] absoluteString]; 

    NSLog(@"Value retured : %@",strResponse); 

    if ([strResponse hasPrefix:@"ios:"]) { 

     NSString *newString = [strResponse substringFromIndex:[@"ios:" length]]; 
     newString = [newString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

     NSLog(@"Value retured : %@",newString); 

     UIAlertView *uiAlert = [[UIAlertView alloc] initWithTitle:@"Message" message:newString delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil]; 
     [uiAlert show]; 

     NSArray *arrItems = [newString componentsSeparatedByString:@":::"]; 
     for (NSString *strItems in arrItems) { 

      [strItems stringByRemovingPercentEncoding]; 
      NSMutableDictionary *mDic = [[NSMutableDictionary alloc] init]; 
      [mDic setObject:strItems forKey:@"item_name"]; 
      [mDic setObject:@"0" forKey:@"is_deleted"]; 
      [[DataBase connection] insertTableData:mDic AndTableName:@"school_feed"]; 
     } 

     return NO; 
    } 
    return YES; 
} 

のInfo.plist enter image description here

+0

あなたは?あなたの 'info.plist'に' NSAppTransportSecurity'と 'CFBundleURLTypes'をクローラしますか? –

答えて

1

は、たとえば、あなたのWebViewロード

webView.delegate = self

に以下のコードを追加します。

のWebViewロード

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-64)]; 
    NSString *htmlFile = [[NSUserDefaults standardUserDefaults] objectForKey:USER_CODE]; 
    NSURL *url = [NSURL URLWithString:htmlFile]; 
    webView.delegate = self; 
    [webView loadRequest:[NSURLRequest requestWithURL:url]]; 
    [self.view addSubview:webView]; 
} 
+0

"webView.delegate = self"の後にセミコロンを入れてください –

+0

@ JithinU.Ahmedはい更新されました。 –

+0

うん!!!それは動作します.... –

0

あなたはios URLスキームハンドラとしてアプリケーションを宣言するために忘れてしまったように見えます。これを行うには、追加info.plistに次のように:

<key>CFBundleURLTypes</key> 
<array> 
    <dict> 
     <key>CFBundleURLName</key> 
     <string>com.myapp.ios</string> 
     <key>CFBundleURLSchemes</key> 
     <array> 
      <string>ios</string> 
     </array> 
    </dict> 
</array> 
関連する問題