let strUrl = bank://bpay?link=https://bpayuat.allsocialassets.com/pay?bid=OU1200000NATGF&cpm=Policy%20Number:217307XX|DOB%20(DD-MMM-YYYY):07-MAR-1985&cnm=BBPS&bnm=10142&bpr=JUNE&bmt=360&bdt=2021%2D06%2D11&&bai=Policy%20Status:active|Product%20Name:ICICI%20Pru%20Heart%20Cancer%20Protect|Premium%20Amount:20&enc_Policy%20Number=4evSBNbzt7iU9xQq6J2nnaCsfb1983yu5EZn9XtMvWxtZG9YMSC4CHa1Rb4CrqZ7cAyjZDKP2boqUh1nCSqygDFN&cid=202289766745
let url = strUrl!.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
let queryItems = URLComponents(string: url!)?.queryItems
let bid = queryItems?.filter({$0.name == "bid"}).first
let bnm = queryItems?.filter({$0.name == "bnm"}).first
let cpm = queryItems?.filter({$0.name == "cpm"}).first
let bmt = queryItems?.filter({$0.name == "bmt"}).first
let cid = queryItems?.filter({$0.name == "cid"}).first
let enc = queryItems?.filter({$0.name == "enc_Policy%20Number"}).first
let bdt = queryItems?.filter({$0.name == "bdt"}).first
let bpr = queryItems?.filter({$0.name == "bpr"}).first
let cnm = queryItems?.filter({$0.name == "cnm"}).first
let bai = queryItems?.filter({$0.name == "bai"}).first
Get the value of URL Parameters for bid i'm getting nil value
110 Views Asked by Pragat Rajput At
1
Your URL is:
You could analyze the query as such:
If it was
&bidinstead of?bid, then thebidwould have been another query item frombpay, but since there isn't, it's a query item frombpayuat.allsocialassets.com/pay.You need to do the same, looking for
URLQueryIteminside the URL parameter.This can also be seen with checking what's you parsed:
Output:
And if you change your URL to (the
&bidinstead of?bid):bank://bpay?link=https://bpayuat.allsocialassets.com/pay&bid=OU1200000NATGF&cpm=Policy%20Number:217307XX|DOB%20(DD-MMM-YYYY):07-MAR-1985&cnm=BBPS&bnm=10142&bpr=JUNE&bmt=360&bdt=2021%2D06%2D11&&bai=Policy%20Status:active|Product%20Name:ICICI%20Pru%20Heart%20Cancer%20Protect|Premium%20Amount:20&enc_Policy%20Number=4evSBNbzt7iU9xQq6J2nnaCsfb1983yu5EZn9XtMvWxtZG9YMSC4CHa1Rb4CrqZ7cAyjZDKP2boqUh1nCSqygDFN&cid=202289766745
You'll get:
Keeping your logic:
Unrelated but:
filter({$0.name == "something"}).firstshould befirst(where: { $0.name == "something" }). It's better optimized.