Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: XCode 8 OpenURL deprecated



Permlink Replies: 6 - Last Post: Aug 15, 2017 1:16 PM Last Post By: Dave Nottage
Chris Dunn

Posts: 160
Registered: 8/22/11
XCode 8 OpenURL deprecated
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 14, 2017 1:06 PM
openurl no longer works in ios 10 with sdk 8.

found some info
https://useyourloaf.com/blog/openurl-deprecated-in-ios10/

how should I modify

unit iOSapi.UIKit;
function openURL(url: NSURL): Boolean; cdecl;

to work correctly in ios10 and up for sdk8?

Thanks,
Chris
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: SDK 8 OpenURL deprecated [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 14, 2017 1:32 PM   in response to: Chris Dunn in response to: Chris Dunn
Chris Dunn wrote:

openurl no longer works in ios 10 with sdk 8.

The old version of it, yes. Apple simply added a new overload of it
that takes additional "options" and "completionHandler" parameters as
input.

how should I modify

unit iOSapi.UIKit;
function openURL(url: NSURL): Boolean; cdecl;

to work correctly in ios10 and up for sdk8?

Ask Embarcadero to add support for it in the next Delphi version. The
old openURL is synchronous, the new openURL is asynchronous. Trying to
rewrite the old openURL to still work synchronously while calling the
new asynchronous openURL would not be easy or efficient.

Besides, just because the old openURL is deprecated doesn't mean it
stops working altogether. You can keep using it for the time being.

--
Remy Lebeau (TeamB)
Chris Dunn

Posts: 160
Registered: 8/22/11
Re: SDK 8 OpenURL deprecated [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 14, 2017 1:36 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...

Besides, just because the old openURL is deprecated doesn't mean it
stops working altogether. You can keep using it for the time being.

it does not work in ios 10 and up.
it does work in ios 9 and down.

the only way to make it work is to switch back to sdk 7
only problem is i cannot debug on ios 10 without sdk 8.

Edited by: Chris Dunn on Aug 14, 2017 1:37 PM
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: SDK 8 OpenURL deprecated [Edit] [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 14, 2017 2:05 PM   in response to: Chris Dunn in response to: Chris Dunn
Chris Dunn wrote:

the only way to make it work is to switch back to sdk 7
only problem is i cannot debug on ios 10 without sdk 8.

What are SDK 7 and 8? Do you mean Xcode?

Here's a possible solution (untested):

type
  TOpenURLCompletionProc = procedure(param1: Boolean) of object;
 
  UIApplication = interface(iOSapi.UIKit.UIApplication)
    ['{CBF4403E-58DD-43A1-B5E9-C459382F0566}']
    [MethodName('openURL:options:completionHandler:')]
    procedure openURLOptionsCompletionHandler(url: NSURL; options: NSDictionary; completionHandler:
TOpenURLCompletionProc); cdecl;
  end;
  TUIApplication = class(TOCGenericImport<UIApplicationClass, UIApplication>) end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
  LApp: UIApplication;
  LOptions: NSDictionary;
begin
  LApp := TUIApplication.Wrap(TUIApplication.OCClass.sharedApplication);
  LOptions := TNSDictionary.Create;
  if TOSVersion.Check(10) then
    LApp.openURLOptionsCompletionHandler(StrToNSURL('http://www.embarcadero.com'), LOptions, OpenURLComplete)
  else
    LApp.openURL(StrToNSURL('http://www.embarcadero.com'));
end;


Where OpenURLComplete is a procedure of the form whose signature looks like this:

  procedure OpenURLComplete(param1: Boolean);


--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
Chris Dunn

Posts: 160
Registered: 8/22/11
Re: SDK 8 OpenURL deprecated [Edit] [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 15, 2017 8:40 AM   in response to: Dave Nottage in response to: Dave Nottage

What are SDK 7 and 8? Do you mean Xcode?
Yes

Here's a possible solution (untested):

type
  TOpenURLCompletionProc = procedure(param1: Boolean) of object;
 
  UIApplication = interface(iOSapi.UIKit.UIApplication)
    ['{CBF4403E-58DD-43A1-B5E9-C459382F0566}']
    [MethodName('openURL:options:completionHandler:')]
    procedure openURLOptionsCompletionHandler(url: NSURL; options: NSDictionary; completionHandler:
TOpenURLCompletionProc); cdecl;
  end;
  TUIApplication = class(TOCGenericImport<UIApplicationClass, UIApplication>) end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
  LApp: UIApplication;
  LOptions: NSDictionary;
begin
  LApp := TUIApplication.Wrap(TUIApplication.OCClass.sharedApplication);
  LOptions := TNSDictionary.Create;
  if TOSVersion.Check(10) then
    LApp.openURLOptionsCompletionHandler(StrToNSURL('http://www.embarcadero.com'), LOptions, OpenURLComplete)
  else
    LApp.openURL(StrToNSURL('http://www.embarcadero.com'));
end;


Where OpenURLComplete is a procedure of the form whose signature looks like this:

  procedure OpenURLComplete(param1: Boolean);


Thanks Dave seems to be working.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: SDK 8 OpenURL deprecated [Edit] [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 15, 2017 10:07 AM   in response to: Dave Nottage in response to: Dave Nottage
Dave Nottage wrote:
Here's a possible solution (untested):

I would suggest a few tweaks:

1. consolidate the redundant calls to StrToNSURL()

2. do not allocating the options dictionary on pre-10 versions.

3. manually call the completion callback on pre-10 versions.

type
  TOpenURLCompletionProc = procedure(success: Boolean) of object;
 
  UIApplication = interface(iOSapi.UIKit.UIApplication)
    ['{CBF4403E-58DD-43A1-B5E9-C459382F0566}']
    [MethodName('openURL:options:completionHandler:')]
    procedure openURLOptionsCompletionHandler(url: NSURL; options: NSDictionary; completionHandler: TOpenURLCompletionProc); cdecl;
  end;
  TUIApplication = class(TOCGenericImport<UIApplicationClass, UIApplication>) end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
  LUrl: NSURL;
  LApp: UIApplication;
  LOptions: NSDictionary;
begin
  LUrl := StrToNSURL('http://www.embarcadero.com'); // <-- call it only once
  LApp := TUIApplication.Wrap(TUIApplication.OCClass.sharedApplication);
  if TOSVersion.Check(10) then
  begin
    LOptions := TNSDictionary.Create; // <-- moved down here
    LApp.openURLOptionsCompletionHandler(LUrl, LOptions, OpenURLComplete);
  end else
  begin
    OpenURLComplete(LApp.openURL(LUrl)); // <-- call the callback on completion
  end;
end;
 
procedure TForm1.OpenURLComplete(success: Boolean);
begin
  // do something...
end;


--
Remy Lebeau (TeamB)
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: SDK 8 OpenURL deprecated [Edit] [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 15, 2017 1:16 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

I would suggest a few tweaks:

Yeah, it was written in about 2 minutes.. thanks :-)

--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02