How can I exract information to convert to vcard - swift

I am creating an app using swift in xcode 10 that would allow user to create digital portfolios viewed in UIview, this UI view will contain their names , portfolio links and other stuff related to their profession. I have not done anything on it yet, I just want to know how can I extract data from the view to convert to vcard so I can share it

So if get it correctly you will have an application that lets a user fill in his information and create a digital portfolio, after that you want to the user to able to share the information outside of the app. I am not exactly sure what you mean by "extract" but on iOS using swift you can share information like this.
Inside your viewController:
override func viewDidLoad() {
super.viewDidLoad()
let items: [Any] = ["Put whatever you want to share in here", URL(string: "https://www.apple.com")!]
let ac = UIActivityViewController(activityItems: items, applicationActivities: nil)
self.present(ac, animated: true)
}
This will bring up the activity controller.

Related

How to get back to the current window from AppDelegate

In my macOS application, I am following a OAuth-Login procedure.
I am authenticating successfully by receiving a code within a url through my custom url, with which I already can get hold of an access_token.
I start the login procedure with the simple click of a button in a ViewController.
The system I log in to then answers with my registered custom url scheme, providing me with a code I have to then use to get an access_token with POST request. This access_token than can be used to make api calls.
My Problem now is that lacking knowledge of how to implement other techniques, I am currently doing all the latter procedure within the AppDelegate function application(_ application: NSApplication, open urls: [URL]).
From my limited understanding this is the way to handle this, but now
how can I get back from there to get hold of the current view? I am really struggling with the view controller life cycle part of things here I guess...
In AppDelegate, you can get a reference to the current window's ViewController as follows. Replace "MainViewController" with the name of the one you use.
iOS Swift:
if let vc = window?.rootViewController as? MainViewController {
// use `vc` here by calling public functions
// and accessing public properties
}
macOS Swift:
if let vc = NSApplication.shared.mainWindow?.contentViewController as? MainViewController {
// use `vc` here by calling public functions
// and accessing public properties
}
OK, found it: since there is no rootViewController in macOS-land as there is with iOS, it works a little different:
in macOS you can get hold of the window currently "under keyboard" like so:
in application(_:open:), where the redirect_uri gets called:
if let viewController = NSApplication.shared.keyWindow?.contentViewController as? ViewController {
// make changes to the view
}

Swift Stripe Access DidCreateToken

I'm trying to integrate Stripe into my ios (Swift) app by using Firebase-Cloud-Functions. Now I'm want to get the token to a created card to save it into my Firestore-Database.
I've followed this tutorial on how to implement it. It's working when I'm displaying my addCardViewController on my own since I have the method didCreateToken. But now that I'm just showing it programmatically like shown in their provided example (row 158 is where they're showing the view controller) I don't know how to implement this method and get the token of the card if a user creates/adds a new one.
Thats what Id normally do:
func addCardViewController(_ addCardViewController: STPAddCardViewController, didCreateToken token: STPToken, completion: #escaping STPErrorBlock)
{
STRIPE_CUSTOMERS_REF.document(userId).collection("tokens").addDocument(data: ["token": tokenId]) // Calls Firebase-Cloud-Function and adds payment method to Stripe
navigationController?.popViewController(animated: true)
}
But like I said Im not able to implement this method.
I want to get the token when a user adds a new card.
Id really appreciates any kind of help. If you need any additional information let me know.
-Marie
It looks like you using STPPaymentContext (Standard Integration) to present the STPPaymentMethodsViewController (line 158 in the example above).
STPPaymentContext actually implements its own instances of STPPaymentMethodsViewController and STPAddCardViewController. Therefore, STPPaymentContext handles the delegate methods for those 2 view controllers and those aren't exposed to the user when using the Standard Integration. Which explains why that delegate method is not triggering for you.
Instead, your view controller should become the delegate for STPPaymentContext and implement the all the required delegate methods [0], including paymentContextDidChange method.
paymentContextDidChange method is triggered whenever a user adds a new card or selects a new payment method [1].
When a user enters new card details, you should be able to get the token ID with the following:
func paymentContextDidChange(_ paymentContext: STPPaymentContext)
{
if let card = paymentContext.selectedPaymentMethod as? STPCard {
let token = card.stripeID
// store token as required
}
}
Hope that helps!
[0] https://stripe.github.io/stripe-ios/docs/Protocols/STPPaymentContextDelegate.html
[1] https://stripe.github.io/stripe-ios/docs/Protocols/STPPaymentMethod.html

Trigger In-App-Browser after tapping on Annotation with PDFKit - iOS 11

I´m working on an app with Apple's PDFKit and have managed to put some Annotation-Buttons with a working PDFActionURL, which open the iOS standard browser after tapping on them.
Unfortunately, I did not find a working solution, how to open the associated links in an In-App-Browser or to load it in a webview. After tapping the AnnotationButton PDFKit automatically opens Safari and I haven´t found a property or another way concerning iOS to influence this behavior by manipulating f.e. the PDFAction.
let urlString = "https://www.apple.com"
let urlAction = PDFActionURL(url: urlString)
urlButton.action = urlAction
pdfPage.addAnnotation(urlButton)
Is there a way to force the call of an In-App-Browser at every UIApplication.shared.open() or to manipulate the execution of a PDFAction?
Finally, I figured it out for myself ;) I´ve overlooked one function of the PDFViewDelegate
By setting the delegate of the pdfView to the involved ViewController and using this function
func pdfViewWillClick(onLink sender: PDFView, with url: URL) {
print(url)
}
you are able to use the associated URL of the PDFActionButton and to trigger an In-App-Browser (e.g. SFViewController).
You want to instantiate the view like so:
let webV:UIWebView = UIWebView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height))
webV.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.google.co.in")))
webV.delegate = self;
self.view.addSubview(webV)
Found HERE
To do it right, I would create a new ViewController in your storyboard, nested in a navigationController and segue to the view on annotation selection. Display your content on viewDidLoad using a similar set of code as seen above. That code is probably in an older version of swift so you'll need to update it. There is more detail about using the delegate associated in the link provided.

Memory Management When Navigating Between View Without Using Navigation Controller

I have been working on iOS application in swift from last 40-45 days. It has around 20 screens. I have implemented google map, payment gateway and many other UI component into it.
My problem is it is showing memory usage around 120 MB in flows which is very high for mobile devices. I did not used navigation controller and I have created all UI component programmatically.
In order to move from one view to another view, I have connected them via segue and in prepare for segue method I am sending data if needed. Given code is moving from one view to another
#IBAction func goToSearchFromHome(searchButton: UIButton) {
self.performSegueWithIdentifier("homeToSearchSegue", sender: self)
}
In order to come on previous page I am using following code:
#IBAction func goToHomePage(homeButton: UIButton) {
let vc = storyboard!.instantiateViewControllerWithIdentifier("homeScreen")
self.presentViewController(vc, animated: true, completion: nil)
}
Ideally, when moving from one screen to another, memory usage should include on that instance of view. What should I do in order to solve my problem?

A way to search location without Map being visible?

I'm new to iOS developing, any help or resources are appreciated!
Is there a way to search for a city, town, state or country using a search bar without having the map visible? I basically want to have the customer type in any location, select it and then view search results in that location that the client added on their controller/log in. I've already created the log in/sign up, eventually I want to integrate Stripe for each search result.
I've tried looking for tutorials online, but only seem to find tutorials based off of having the actual Map visible and inputting regular text.
Yes, you can initialize a uisearchbar without tying it to a map. You then make your class a delegate and tell it how to handle searches. The following is in Swift 2
First, make your class a delegate:
class yourClass: UISearchBarDelegate
Initialize the controller
var searchController: UISearchController!
searchController = UISearchController(nil) // nil means you want to show the results on the same page as the search
Then, in whatever action will present the search:
self.presentViewController(searchController, animated: true, completion: nil)
Now you tell it how to handle a search using one or more of these methods:
func searchBar(UISearchBar, textDidChange: String) //the user changed the search text
func searchBarTextDidEndEditing(UISearchBar) // user stopped changing search text
func searchBarSearchButtonClicked(searchBar: UISearchBar) // user clicked "Search"
According to the docs:
At a minimum, the delegate needs to perform the actual search when text is entered in the text field.
So using any of those methods should meet the minimum requirement
See here for the full docs