CFBundleURLSchemes Custom URI Scheme [SOLVED]
lazarus / 33-macOS - Mac OS X
----------------------------------------------------------------------
xenon54 · 2020-05-20 14:38
Hi all!
In my OX S application, i need to inbound external interraction.
This is open my app when double click for file with .myapp extensions
and open it with custom uri scheme.
For the first case, i found extra simple solution -
https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-
macos-x-how-to-open-with-for-files-that-open-with-your-application/
For the second case, i found nothing... Can anyone help me with this?
I know, that i must register ".myapp" in plist.list by adding this.
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
CFBundleURLTypes
CFBundleURLName
MYAPP
CFBundleURLSchemes
myapp
And application opens by this uri.
But how to parse uri inside application? Somthing like
"TForm1.ApplicationProperties1DropFiles" event.
----------------------------------------------------------------------
trev · 2020-05-21 07:39
Quote from: xenon54 on May 20, 2020, 04:38:09 pmFor the first case, i
found extra simple solution -
https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-
macos-x-how-to-open-with-for-files-that-open-with-your-application/
Code: XML [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
CFBundleURLTypes
CFBundleURLName
MYAPP
CFBundleURLSchemes
myapp
Apple "This key contains the abstract name for this URL type. This is
the main way to refer to a particular type. To ensure uniqueness, it
is recommended that you use a Java-package style identifier." The
highlighted line should therefore be more like:
Code: XML [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
com.yourdomain.myapp
Additionally, you might also consider including:
Code: XML [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
CFBundleTypeRolerole
where role is one of: Editor, Viewer, Shell, QLGenerator, None.
[EDIT]
As to the second part of your question, this looks apposite.
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i myDocument
= objcclass(NSDocument) public function getName : NSString;
message 'getName'; function getfileURL: NSURL; message 'fileURL';
end;
----------------------------------------------------------------------
xenon54 · 2020-05-21 10:40
Thank you very much for the answer. Can you explain me how to use it?
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i myDocument
= objcclass(NSDocument) public function getName : NSString;
message 'getName'; function getfileURL: NSURL; message 'fileURL';
end;
I'm trying do this
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i type
myDocument = objcclass(NSDocument) public function getName :
NSString; message 'getName'; function getfileURL: NSURL; message
'fileURL'; end; ..... implementation procedure
TForm1.FormCreate(Sender: TObject);begin
ShowMessage(myDocument.getName);
ShowMessage(myDocument.getfileURL); end;
But getting errors:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
unit1.pas(66,33) Error: Only class methods, class properties and class
variables can be accessed in class methods
Looks like this is abstract class and this methods need
implementation.
And how to convert NSString to string?
UPD: For this question i find answer:
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i uses
CocoaUtils; function NSStringToString(ns: NSString): String;
----------------------------------------------------------------------
trev · 2020-05-21 11:32
I discovered a simpler non-macOS API method. Easier to demo than
explain
Demo project attached. Opens .xyz files.
[EDIT]
Info.Plist to replace default created by Lazarus.
Code: XML [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i CFBundleDevelopmentRegion
English CFBundleExecutable
SimpleEditor CFBundleName
SimpleEditor CFBundleIdentifier
com.company.SimpleEditor
CFBundleInfoDictionaryVersion 6.0
CFBundlePackageType APPL
CFBundleSignature Simp
CFBundleShortVersionString 0.1
CFBundleVersion 1
CSResourcesFileMapped
CFBundleDocumentTypes
CFBundleTypeRole
Editor
CFBundleTypeExtensions
xyz
CFBundleTypeOSTypes
fold
disk
****
NSHighResolutionCapable
----------------------------------------------------------------------
xenon54 · 2020-05-21 11:49
Quote from: trev on May 21, 2020, 01:32:36 pmI discovered a simpler
non-macOS API method. Easier to demo than explain
Demo project attached. Opens .xyz files.
Your demo about open files with custom extension. This is i can ddo.
I need open application by custom URI and parse it when app opened.
----------------------------------------------------------------------
trev · 2020-05-21 12:02
Am I misunderstanding?
If you double-click on a file (you'll need to re-assemble the
Info.plist file as the publish project doesn't preserve it), then you
can get the filename and path from the FormDropFiles() FileNames[0].
Is that not what you wanted?
----------------------------------------------------------------------
xenon54 · 2020-05-21 12:33
Quote from: trev on May 21, 2020, 02:02:13 pmAm I misunderstanding?
If you double-click on a file (you'll need to re-assemble the
Info.plist file as the publish project doesn't preserve it), then you
can get the filename and path from the FormDropFiles() FileNames[0].
Is that not what you wanted?
How to get filename from double click i know
There is link in my first message to easy way for it.
I need other.
If in browser write "myapp://12345", opens my application. In
Application i need to know this string.
I have delphi file, that include what i need (TURLEventHandler), but i
cant do this for lazarus.
----------------------------------------------------------------------
trev · 2020-05-22 09:00
See https://kaihao.dev/posts/Make-your-own-custom-URI-scheme-resolver
Be warned though - it does not appear to work for me and given that it
is a security issue (it has been used by malware in the last couple of
years), it's possible it has been "deprecated" out of existence.
----------------------------------------------------------------------
xenon54 · 2020-05-22 12:03
Quote from: trev on May 22, 2020, 11:00:59 amSee
https://kaihao.dev/posts/Make-your-own-custom-URI-scheme-resolver
Be warned though - it does not appear to work for me and given that it
is a security issue (it has been used by malware in the last couple of
years), it's possible it has been "deprecated" out of existence.
I Think this is bad way...
Would be better natively in lazarus.
----------------------------------------------------------------------
trev · 2020-05-22 12:43
The first part is easy to resolve in Lazarus by extending the
Info.plist file:
Code: XML [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
CFBundleURLTypes
CFBundleTypeRole
Viewer
CFBundleURLName
com.company.SimpleEditor.URLScheme
CFBundleURLSchemes
xyz
So, Safari will then ask you if you want SimpleEditor to open if you
give it "xyz://blah".
However, you now need to find a way to actually open the file "blah".
Apple documentation for this.
----------------------------------------------------------------------
trev · 2020-05-22 12:50
See: this post.
----------------------------------------------------------------------
xenon54 · 2020-05-22 14:21
Quote from: trev on May 22, 2020, 02:50:15 pmSee: this post.
This is what I need, thanks a lot.
But i have same errors in linker as topic starter.
http://prntscr.com/slszja
Im trying to paste into Project options -> Compilation and Linking
http://prntscr.com/slt1ft
But getting errors
http://prntscr.com/slt1up
----------------------------------------------------------------------
xenon54 · 2020-05-22 14:31
Ok, i just commented in uses "AppleEvents" and all workds fine. Link
that you give - is awesome. Dont know why my search not give me this
result. Thanks again.
----------------------------------------------------------------------
trev · 2020-05-23 01:50
Glad we got there in the end