Posts

Showing posts from July, 2024

Open maps with lat,long and link based iOS swift

 Problem: I want a common function that i can handle one location object with lat,long and address.That address can have a link that copied from other apps like google maps,Apple maps and whatsapp. Also want save option that will save the location into my app local database. How to achieve all the above us. Solution: func   openMaps ( lat :   Double , long :   Double , address : String   =   "" , isSave : Bool   =   true ) {       let   addressURL =   URL ( string : address. trimStr   ??   "" )       if   let   topview =   UIApplication . topViewControlle r () {           if   (lat != 0 && long != 0) {               let   actionSheet =   UIAlertController ( title :   "" ,   message :   "" ,   preferredStyle : . actionSheet )               if   let   add = addressURL, UIApplication . share d . canOpenURL (add) {                   actionSheet. addAction ( UIAlertA ction ( title :   "Open" ,   style : . default ,   handler : { _  

iOS Launch screen came as black

 Problem: My app have launch screen and i had assigned in storyboard also configured in info.plist.But it came as black screen. Solution: If launchscreen came as black if the following situation 1.Have to check that you had a storyboard with launchscreen viewcontroller as initviewcontroller 2.Also have to check that name is configured in the info.plist file for launchscreen 3.If you are using any images in launchscreen please remove and check if the image persist the issue.

While rotate to landscape some view on top shown because of status bar custom view in swift

 Problem: while rotate to landscape some view on top shown because i had added one custom view for status bar.How to avoid that? Solution: First you have to set the tag to the view that you are added for customisation. Then follow the code.      override   open   func   viewDidLayoutSubviews () {          super . viewDidLayoutSubviews ()                  if   let  statusView =  self . view . viewWithTag (9999) {            statusView. isHidden  =  UIDevice . current . orientation . i sLandscape         }     }      override   var   prefersStatusBarHidden :  Bool  {          return   UIDevice . current . orientation . i sLandscape     } You can hide the view while from landscape then if it rotated to portrait it will automatically shown.

app to be portaraint and particular screen will be landscape swift

 Problem: I had enabled portrait and landscape in info.plist but i want to enable one screen in landscape allowed and other screens only on portrait.How to achieve that? Solution: First you must enable the both portrait and landscape in info.plist.Then add the below code in appdelegate      func   application ( _  application:  UIApplication ,  supportedInterfaceOrientations For  window:  UIWindow ?) ->  UIInterfaceOrientationMask  {          if   let  vc =  UIApplication . topViewControlle r ()  as ? my viewController  {              // Only allow portrait (standard behaviour)              print ( "landscape called" )              return  . all ;         }          print ( "portrait called" )          return  . portrait ;     } Then it will be working fine.Happy coding..