第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何從Javascript調(diào)用Object-C?

如何從Javascript調(diào)用Object-C?

紫衣仙女 2019-07-15 14:58:58
如何從Javascript調(diào)用Object-C?我有一個(gè)WebView,我想從JavaScript調(diào)用Object-C中的一個(gè)視圖。有人知道我該怎么做嗎?我的ViewController中有以下代碼:- (BOOL)webView:(UIWebView *)webView2   shouldStartLoadWithRequest:(NSURLRequest *)request   navigationType:(UIWebViewNavigationType)navigationType {  NSString *requestString = [[request URL] absoluteString];  NSArray *components = [requestString componentsSeparatedByString:@":"];  if ([components count] > 1 &&    [(NSString *)[components objectAtIndex:0] isEqualToString:@"myapp"]) {   if([(NSString *)[components objectAtIndex:1] isEqualToString:@"myfunction"])    {    NSLog([components objectAtIndex:2]); [[Airship shared] displayStoreFront]; //<- This is the code to open the Store    NSLog([components objectAtIndex:3]); // param2    // Call your method in Objective-C method using the above...   }   return NO;  }  return YES; // Return YES to make sure regular navigation works as expected.}在Javascript中:function store(event){     document.location = "myapp:" + "myfunction:" + param1 + ":" + param2;}但什么都沒發(fā)生。
查看完整描述

3 回答

?
慕虎7371278

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超4個(gè)贊

標(biāo)準(zhǔn)的解決辦法UIWebView是設(shè)置一個(gè)UIWebViewDelegate,并實(shí)現(xiàn)了該方法。webView:shouldStartLoadWithRequest:navigationType:..在JavaScript代碼中,導(dǎo)航到某個(gè)偽URL,該URL編碼要傳遞給應(yīng)用程序的信息,例如:

window.location = "fake://myApp/something_happened:param1:param2:param3";

在委托方法中,查找這些假URL,提取所需的信息,采取任何適當(dāng)?shù)牟僮鳎缓蠓祷亍?/trans>NO取消導(dǎo)航。使用一些味道.performSelector.


查看完整回答
反對 回復(fù) 2019-07-15
?
catspeake

TA貢獻(xiàn)1111條經(jīng)驗(yàn) 獲得超0個(gè)贊

不推薦從JS調(diào)用目標(biāo)c的window.Location方法。問題的一個(gè)例子:如果你連續(xù)打了兩個(gè)電話,其中一個(gè)被忽略了(因?yàn)槟悴荒芴斓馗淖兾恢?-你自己試試吧。

我建議采取以下替代辦法:

function execute(url) {
  var iframe = document.createElement("IFRAME");
  iframe.setAttribute("src", url);
  document.documentElement.appendChild(iframe);
  iframe.parentNode.removeChild(iframe);
  iframe = null;}

你打電話給execute函數(shù),由于每個(gè)調(diào)用都在自己的iframe中執(zhí)行,因此在快速調(diào)用時(shí)不應(yīng)忽略它們。

貸給這家伙.


查看完整回答
反對 回復(fù) 2019-07-15
  • 3 回答
  • 0 關(guān)注
  • 699 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號