Tab bar items image doesn't appear after presentview - ios

I coded my application with Swift 2. When i was trying to create my application, i used this code after user login successfully
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("home") as! UITabBarController
self.presentViewController(vc, animated: true, completion: nil)
vc is a UITabBarController which has 3 UIViewController. After TabBar appears only selected TabBar's item's image appears. All the other images appears after 10 seconds or if i touch any of them it appears. If I set TabBarController as an initial view images appears successfully.
I checked the RAM status and application uses 14.5 mb on iPhone 6 plus so i don't think happens because of memory leak.
I searched everywhere but i couldn't find any problem same as mine.
SOLVED:
I was using Touch ID in my code and this presentviewcontroller code was in completion. Raywenderlich handled completion with treads like this.
authContext.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: "Testing Touch ID", reply: { (complete, error) -> Void in
dispatch_async(dispatch_get_main_queue(), {
if complete {
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("home") as! UITabBarController
self.presentViewController(vc, animated: true, completion: nil)
}
else{
}
})
})
I change my code like this and it worked fine. I edited my answer maybe this is a Xcode bug or else.

Related

How do I dismiss an ORKTaskViewController and present a view controller of my choice?

I've spent 24 hours trying to find a solution for this issue. When a user hits register on my app they will have to answer a series of survey questions (which I created using an ORKorderedtask (research kit)). Once the survey is completed I'd like the home page to be presented, however when I test the app and finish the survey it goes straight back to the register page. here's my code:
1.presenting the ordered task view controller;
let registrationTaskViewController = ORKTaskViewController(task: registrationSurvey, taskRun: nil)
registrationTaskViewController.delegate = self
self.present(registrationTaskViewController, animated: true, completion: nil)
2. Dismissing the task view controller(this doesn't work);
func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {
self.dismiss(animated: false) {
let home = homePageViewController()
self.present(home, animated: true, completion: nil)
}
thanks in advance.
Without knowing all the ViewControllers in your stack, I'd suggest not dismissing your register page view controller. Instead present your HomePageViewController on top of your Register screen. Just change your delegate method to this:
func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {
let home = homePageViewController()
self.present(home, animated: true, completion: nil)
}
Or you could even present your HomePageViewController in the completion block after you prsent your ORKTaskViewController. The benefit of this approach would be that when the user dismisses the survey, they will see the HomePageViewController immediately:
let registrationTaskViewController = ORKTaskViewController(task: registrationSurvey, taskRun: nil)
registrationTaskViewController.delegate = self
self.present(registrationTaskViewController, animated: true, completion: {
let home = homePageViewController()
self.present(home, animated: true, completion: nil)
})
A couple more points:
• Classes should begin with capital letters (i.e. HomePageViewController). It's a convention that every single experienced developer uses, and Apple even recommends.
• Ultimately, I would suggest using a Navigation Controller to handle these transitions. With Nav Controllers you can achieve a much better 'flow' using push segues. It just feels better.

A delegate has not been set on an instance of GMSPlacePickerViewController before us

I've been playing around for couple days with IOS and Google Maps Api and two days ago the API was upgraded to the version 2.3 which deprecate the use of GMSPlacePicker.
Deprecation notice: GMSPlacePicker
Notice: The implementation of the place picker has changed. As of version 2.3 of the Google Places API for iOS, the GMSPlacePicker class is deprecated, replaced by GMSPlacePickerViewController. Use of the GMSPlacePicker class will only be supported until May 1, 2018. We recommend that you update your code to use GMSPlacePickerViewController when possible.
In my code I switched to GMSPlacePickerViewController however I still get an error on the logs saying :
Places API warning: A delegate has not been set on an instance of GMSPlacePickerViewController before use. Note that this may result in undefined behavior such as being unable to dismiss screens, not being notified of selections, and being unable to correctly manage object lifecycle.
Even though my class is extending the delegate
class ReportController: UIViewController,UIPickerViewDelegate,UIPickerViewDataSource,GMSPlacePickerViewControllerDelegate{
// code goes here
}
Any idea how to solve this ?
I had also the same problem I resolved this by using this code.
Here is the code .
let config = GMSPlacePickerConfig(viewport: nil)
let placePicker = GMSPlacePickerViewController(config: config)
placePicker.delegate = self
present(placePicker, animated: true, completion: nil)
Hope this will also resolve your problem
GoogleMap version 2.3
The document also make me feel confuse in version 2.3
The picture below is a picture that I crop from the google document.
This link is a document from google map SDK for this Solution
you just write the code according to document and add a one line of code below the code was accentuated by the red pen.
The code that I wrote accordingly from document below here
// The code snippet below shows how to create and display a GMSPlacePickerViewController.
#IBAction func pickPlace(_ sender: UIButton) {
let config = GMSPlacePickerConfig(viewport: nil)
let placePicker = GMSPlacePickerViewController(config: config)
placePicker.delegate = self
present(placePicker, animated: true, completion: nil)
}
// To receive the results from the place picker 'self' will need to conform to
// GMSPlacePickerViewControllerDelegate and implement this code.
func placePicker(_ viewController: GMSPlacePickerViewController, didPick place: GMSPlace) {
// Dismiss the place picker, as it cannot dismiss itself.
viewController.dismiss(animated: true, completion: nil)
print("Place name \(place.name)")
print("Place address \(String(describing: place.formattedAddress))")
print("Place attributions \(String(describing: place.attributions))")
}
func placePickerDidCancel(_ viewController: GMSPlacePickerViewController) {
// Dismiss the place picker, as it cannot dismiss itself.
viewController.dismiss(animated: true, completion: nil)
print("No place selected")
}

Trying to Open SFSafariViewController in AppDelegate via Push Notification

I am trying to open a URL using Safari when the app gets a push notification. This works successfully when the app is in the first viewcontroller. But if the app is further into the program I get an error
<SFSafariViewController: 0x10b20ae60> on <AdViewController: 0x100b14530> whose view is not in the window hierarchy!
(AdViewController is my first view controller, so it is still focused on that one. )
I have searched this site and have tried all the suggestions for this error but have come up short. Currently, my code looks like this:
if MessageUrl != nil , let url = URL(string: MessageUrl!) {
let safari = SFSafariViewController(url: url)
self.window?.rootViewController?.presentedViewController?.present(safari, animated: true, completion: nil)
}
Get top most UIViewController I used extension UIApplication in Appdeleagte from the "swift 3" answer at bottom of that page and changed my code to:
if MessageUrl != nil , let url = URL(string: MessageUrl!) {
let safari = SFSafariViewController(url: url)
UIApplication.topViewController()?.present(safari, animated: true, completion: nil)
}

Why am I getting a black screen when I use self.presentViewController(vc, animated: true, completion: nil) Xcode swift 2

So I'm try to set up a login func (which worked) but when I test the login, I get to the login screen and login in. Then It shows a black screen.
func login(){
FIRAuth.auth()?.signInWithEmail(Username.text!, password: Password.text!, completion: {
user, error in
if error != nil{
print("Incorrect Username/Password")
}
else{
print("Welcome")
self.presentViewController(vc, animated: true, completion: nil)
}
})
}
Can anybody tell me what I am doing wrong.
The signInWithEmail part doesn't affect the UIview.
Storyboard name I'm new to this but the following answer worked for me
let NextView = self.storyboard?.instantiateViewControllerWithIdentifier("xyzVC") as! xyzVC
self.presentViewController(NextView, animated: true, completion: nil)
used the following answer
https://stackoverflow.com/a/30248306/6679536
again, I'm new, so maybe this will create issues in the future!
make sure you call the ViewController in storyboard the exact same name, as shown in the picture... otherwise you will get a huge error.

How to do logout with Parse Swift iOS 8 Xcode 6.4

How do I log out with Parse Swift iOS 8 Xcode 6.4?
Here's a screenshot.
I need to add the action for my button so that I can log out with Parse.
http://i.gyazo.com/905df0a5f4bf29e7dd1a2b44e0c35865.png
Please help.
Thanks,
Jamie Mathieson
After you are log out you need to present the LoginView Controller or Sign up
PFUSer.logout()
let Login = storyboard.instantiateViewControllerWithIdentifier("someViewController") as! UIViewController
self.presentViewController(Login, animated: true, completion: nil)
PFUser.logOutInBackground(block: { (error) in
if error == nil {
// Show whatever screen you want here
let loginVC = self.storyboard?.instantiateViewController(withIdentifier: "ViewControllerID") as! Wizard
self.present(loginVC, animated: true, completion: nil)
}})

Resources