Issue
I created a Xamarin forms application and configured custom URL Scheme for iOS but it didn't fire in iOS 14.
So I created a sample native iOS project and test custom URL Scheme and it is working. This is the sample iOS swift code.
import SwiftUI
@main
struct TestApp: App {
//@UIApplicationDelegateAdaptor var delegate: AppDelegate
var body: some Scene {
WindowGroup {
ContentView().onOpenURL(perform: handleURL)
}
}
func handleURL(_ url: URL) {
print("source application")
print(url)
}
}
But how can I convert this same to Xamarin. Because how to call onOpenURL in Xamarin iOS?
Solution
Add info about your custom scheme in your info.plist. You can do this in your iOS Project Options:
Double-click your iOS project >> Build > iOS Application >> Advanced (tab)
At the bottom, you'll see a section URL Types. Add your info about your custom scheme there. For example:
In the "Identifier" field, enter "com.myapp.urlscheme". In the "URL Scheme" field, enter "myapp".
Next you need to override in your AppDelegate file:
public override bool OpenUrl (UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
{
// custom stuff here using different properties of the url passed in
return true;
}
Go ahead and set a breakpoint on "return true" in the override above
Now if you build and run on the simulator, then enter "myapp://com.myapp.urlscheme" into the url bar in Safari (on the simulator), it should launch your app, hit your breakpoint, and the "url" param will be "myapp://com.myapp.urlscheme".
Answered By - Adrain Zhu -MSFT
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.