snapkit login kit not working Swift Xcode 11.3.1 - swift

I am using Xcode 11.3.1 and try to login with snapchat with loginkit I add the add information in info.plist and my code is
SCSDKLoginClient.login(from: self, completion: { success, error in
if let error = error {
print(error.localizedDescription)
return
}
if success {
self.fetchSnapUserInfo() //example code
}
})
this code show me the login ui of snapchat and I am login into snapchat with my account.
but I am stuck on this ui
when I am click on continue nothing is happing . SCSDKLoginClient completion block not called.

Please ensure your URL scheme is configured correctly.
URL Schemes

hello everyOne soo finally i found the solution
i am using 11.3.1 and when i create new project the add
AppDelegate and SceneDelegate default class.
so according to snapchat logkit documentation i add
func application(_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return SCSDKLoginClient.application(app, open: url, options: options)
}
method in my Appdelegate class. but this method never get called in xocode 11.3.1
so the solution of my problem is this
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else {
return
}
SCSDKLoginClient.application( UIApplication.shared, open: url, options: nil)
}
you need to add this method into your sceneDelegate file. then everything work fine.
synpchat need to update there doc for new xcode 11.3.1. i hope this answer help you guy's because i also wast my 3 day's on this issue.
happy Coding :)

Related

Flutter IOS Universal Link Opens App, But Does Not Navigate To Correct Page

I have set up Universal Links on my flutter project for IOS.
Like the title suggests, my app does open when I click on a link relating to my site but it does not navigate to the correct page. It just opens the app.
I'm not using the uni_links package, rather I used a combination of guides (including official documentation):
https://developer.apple.com/videos/play/wwdc2019/717/
https://nishbhasin.medium.com/apple-universal-link-setup-in-ios-131a508b45d1
https://www.kodeco.com/6080-universal-links-make-the-connection
I have setup my apple-app-site-association file to look like:
{
"applinks": {
"details": [
{
"appIDs": [
"XXXXXXX.com.my.appBundle"
],
"componenents": [
{
"/": "/*"
}
]
}
]
}
}
and I have added this to my info.plist file:
<key>FlutterDeepLinkingEnabled</key>
<true/>
and my AppDelegate.swift file looks like:
import UIKit
import Flutter
import Firebase
#UIApplicationMain
#objc class AppDelegate: FlutterAppDelegate {
override func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
// This will allow us to check if we are coming from a universal link
// and get the url with its components
// The activity type (NSUserActivityTypeBrowsingWeb) is used
// when continuing from a web browsing session to either
// a web browser or a native app. Only activities of this
// type can be continued from a web browser to a native app.
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL,
let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
return false
}
// Now that we have the url and its components,
// we can use this information to present
// appropriate content in the app
return true
}
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
My Runner-entitlements are also setup correctly like:
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:www.example.com</string>
<string>applinks:*.example.com</string>
</array>
The issue is, if I click a hyperlink for www.example.com/mypath , it does not got to the page/route handled by /mypath, but instead just opens the app.
My routing is done using go_router: ^5.2.4
Please does anyone know why this is happening? I'm blocked by this. I have seen similar questions, but none with answers that have worked for me. Any help is appreciated.
Ok so figured it out. The official apple documentation requests the addition of a variation of this function in the AppDelegate.swift file:
func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
// This will allow us to check if we are coming from a universal link
// and get the url with its components
// The activity type (NSUserActivityTypeBrowsingWeb) is used
// when continuing from a web browsing session to either
// a web browser or a native app. Only activities of this
// type can be continued from a web browser to a native app.
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL,
let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
return false
}
// Now that we have the url and its components,
// we can use this information to present
// appropriate content in the app
return true
}
Seems that it conflicts with the flutter framework for handling universal links. Taking that function out and just having this in my info.plist worked (everything else stayed the same):
<key>FlutterDeepLinkingEnabled</key>
<true/>
Flutter documentation is not out for this (as at the time of posting this answer) so if people are interested, I could do a small article on the necessary steps.
When you handle the dynamic link you get the universal link and other data in the userActivity parameter of the following function.
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if let incomingURL = userActivity.webpageURL {
debugPrint("incoming url is", incomingURL)
let link = DynamicLinks.dynamicLinks().shouldHandleDynamicLink(fromCustomSchemeURL: incomingURL)
print(link)
let linkHandle = DynamicLinks.dynamicLinks().handleUniversalLink(incomingURL) { link, error in
guard error == nil else {
print("Error found.")
return
}
if let dynamicLink = link {
self.handleDynamicLinks(dynamicLink)
}
}
if linkHandle {
return true
} else {
return false
}
}
return false
}
Parse the data from another function or you can parse in above code also. In my case I parsed the code in below function.
func handleDynamicLinks(_ dynamicLink: DynamicLink) {
guard let link = dynamicLink.url else {
return
}
if let landingVC = self.window?.rootViewController as? LandingViewController {
// Do you your handling here with any controller you want to send or anything.
}
// example you are getting ID, you can parse it here
if let idString = link.valueOf("id"), let id = Int.init(idString) {
print(id)
}
}
When you get the details from the link you can simply fetch the navigation controller or the VisibleController, and then can push to the desired flow.

Flutter iOS close SFSafariViewController after stripe payment is complete

I've integrated stipe payment into a Flutter (using this plugin https://pub.dev/packages/stripe_payment) app and it all works fine except for the fact that stripe's 3d secure safari view controller is never closed after the payment is complete so the users must always close it by hand which is not too good
In my AppDelegate.swift I've implemented an application method override like so
override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if (url.absoluteString.contains("stripe")) {
/// this code works and I see in in console
print("STRIPE CALLBACK WORKED");
return true;
}
return false
}
I've also added a deep link to be called by safari when the job is done
var paymentIntentResult = await StripePayment.confirmPaymentIntent(
PaymentIntent(
clientSecret: clientSecret,
paymentMethodId: paymentMethodId,
returnURL: 'mycoolapp://stripe-redirect',
),
);
and indeed the link is called, I can clearly see "STRIPE CALLBACK WORKED" output in xcode's console.
So the question is why doesn't the sfsafariviewcontroller close and the process does not return to the Flutter app by itself?
Instead I see this window
I even tried to remove it by hand using different hacks, like this for example
func popAfterDelay(view uiViewController:UIViewController?) {
print("POP AFTER DELAY CALLED")
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
if (uiViewController is SFSafariViewController) {
print("DISMISS SAFARY VIEW..........")
let safariController = uiViewController as? SFSafariViewController;
safariController?.removeFromParent()
}
}
}
override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if (url.absoluteString.contains("stripe")) {
let curView = ViewUtils.getCurrentViewController();
if (curView != nil) {
popAfterDelay(view: curView)
}
return true;
}
return false
}
I could see "DISMISS SAFARY VIEW.........." output but to no avail.
I'm completely stuck with this. Any help would be highly appreciated

How do I access The URL shared over an Activity Sheet in iOs [duplicate]

This question already has answers here:
URL Opening Swift App - Open Works - Called Function Does NOT work
(3 answers)
Closed 12 months ago.
I am trying to import a PDF to my App through Safari via activity sheet. My app pops up on the activity sheet but I cannot access the URL.
I have tried using the application(_:open:options:) function in my app delegate but it's not working
url handling function
func application(_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool{
print(url)
return true
}
I found the solution here Using Scene Delegate Functions To Receive Urls
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
print(URLContexts.debugDescription)
}

Deep link into macOS app is not recognized

I'm trying to implement a deep link into an macOS application, but nothing seems to work.
So far, my AppDelegate.swift contains the following
func application(app: NSApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
print("opened by link");
return true
}
I also configured the info.plist with URLSchemes beeing my bundle identifier and URLIdentifier beeing simply zst
In a simple html-file I use the following code to test the deep link
Test
My app gets opened (or becomes active when already running), but the print statement is not executed.
What am I doing wrong here?
Thanks to #Ssswift I found a solution.
Used this code:
How do you set your Cocoa application as the default web browser?
and converted it to swift with: https://objectivec2swift.com
works with Swift 3
in AppDelegate.swift added these lines
func applicationDidFinishLaunching(_ aNotification: Notification) {
var em = NSAppleEventManager.shared()
em.setEventHandler(self, andSelector: #selector(self.getUrl(_:withReplyEvent:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
}
func getUrl(_ event: NSAppleEventDescriptor, withReplyEvent replyEvent: NSAppleEventDescriptor) {
// Get the URL
var urlStr: String = event.paramDescriptor(forKeyword: keyDirectObject)!.stringValue!
print(urlStr);
}

application openURL in Swift

I am having an issue with the Appdelegate method OpenURL.
I have setup my Imported UTI's and Document Type. But when opening my app from a mail attachment, the app crashes immediately when I have the method implemented.
The depreciated handleOpenURL works, but not OpenURL?
At the moment I have no code in the implementation, and am just returning true.
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject?) -> Bool {
return true
}
The crash says Thread 1: EXC_BAD_ACCESS (code-1, address-0x0)
I don't really want to have to use the deprecated method.
I have my head blow for a week with this issue.
My app keep crashing after Login Using Social Media Such as Wechat / LinkedIn.But Facebook and Google Sign in Works Fine.
I have notice my app will keep crash after confirm sign in on Wechat Apps and will enter foreground.and Getting BAD EXCESS error. I have try to remove my application open url method on AppDelegate and the app wont crash but the action for Social Media Login are not functioning. so I detect that my issue was on the specific method. after search the web I found that im using an deprecated method of ApplicationOpenUrl as reference from https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623073-application
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return true
} // this method is deprecated in iOS 9 https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623073-application
notice that the deprecated version are using annotation:Any which will cause issue if you had bridging to an Obj-c framework such as wechat.
So what I do was, I swap my code into a the new format
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String
let annotation = options[UIApplicationOpenURLOptionsKey.annotation]
let application = app
return true
}
Hope this help. it will became my reference in feature also. thanks StackOverflow
This is fairly typical of a signature mismatch between the method signatures automatically generated by the Swift compiler and the actual signature. It happens when you try to pass nil from Objective-C into a Swift explicitly unwrapped optional. Change the annotation parameter to be implicitly unwrapped and you should be gtg.
Swift 5 version of Muhammad Asyraf's answer:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
let sourceApplication = options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String
let annotation = options[UIApplication.OpenURLOptionsKey.annotation]
return true
}