0

Language Used: Swift 2.3

Viber's url scheme for sending a message is viber://forward?text=

Whatsapp's url scheme for sending a message is whatsapp://send?text=

The problem is NSURL seems to think that url's that don't have . on them are not urls because this code seems to result to nil

let someString = "This is some kind of long string"
print(NSURL(string: "viber://forward?text=\(someString)"))

print(NSURL(string: "viber://whatsapp://send=\(someString)"))

This results to a log which looks like this.

nil
nil

Which means I can't use UIApplication.sharedApplication().openUrl(someUrl)

molbdnilo
  • 55,783
  • 3
  • 31
  • 71
Zonily Jame
  • 3,917
  • 2
  • 22
  • 43

1 Answers1

1

There are some characters that can't be placed inside a URL/NSURL.

You'd have to parse someString to replace these characters using this String extension

stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())

For example:

var someString = "This is some kind of long string"

someString = someString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())
Zonily Jame
  • 3,917
  • 2
  • 22
  • 43