From Xojo Documentation

Revision as of 15:51, 2 July 2020 by PLefebvre (talk | contribs) (Added sample code)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Class (inherits from Object)

Used when callings declares that require Obj-C blocks. An iOSBlock is created from a Delegate and in turn creates an Objective-C block that will call into the delegate. This Objective-C block is retrieved from the Handle property and passed into declares.

Handle fa-lock-32.png

Constructor(theDelegate As Object)

Sample Code

The openURL command can be called with a series of Declares, the last of which requires a Block. Here are the Declares:

Public Function ShowURL(url As Text) as Boolean
// NSString* launchUrl = @";
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString: launchUrl]];

Declare Function NSClassFromString Lib "Foundation" (name As CFStringRef) As Ptr
Declare Function sharedApplication Lib "UIKit" Selector "sharedApplication" (obj As Ptr) As Ptr
Dim sharedApp As Ptr = sharedApplication(NSClassFromString("UIApplication"))

Declare Function URLWithString Lib "Foundation" Selector "URLWithString:" ( id As Ptr, URLString As CFStringRef ) As Ptr
Dim nsURL As Ptr = URLWithString(NSClassFromString("NSURL"), url)

Declare Function openURL Lib "UIKit" Selector "openURL:options:completionHandler:" (id As Ptr, nsurl As Ptr, options As Ptr, handler As Ptr) As Boolean

Dim b As New iOSBlock(AddressOf URLResult)

Return openURL(sharedApp, nsURL, Nil, b.Handle)
End Function

URLResult is a global method with this Declaration:

Public Sub URLResult(success As Boolean)
// Your code here, although nothing is required
End Sub

See Also

Declare command, Ptr data type