Posts

Showing posts from 2017

Storyboard error after commit from github or sourcekit conflict changes

Solution: Its because of derived data cache.no worries if you had changed from sourcecode in story board if it was no errors then quit the xcode and reopen it again.The storyboard will works fine...

Fetch the objects from Coredata and return it as NSMutableArray iOS Swift

Solution: If you have to fetch the array of objects form coredata and display it in a tableView then don't worry here is the example. The below example had the fetch the objects from coredata orderedobjects also it had a condition with except the particular value fetch all the object predicate also there.Finally return the fetched objects using predicate from coredata.  func getallData () -> NSMutableArray {     let myArr: NSMutableArray = NSMutableArray ()     let appDelegate = UIApplication . shared . delegate as ! AppDelegate     //create a fetch request, telling it about the entity     let fetchRequest: NSFetchRequest < ENTITY > =  ENTITY . fetchRequest ()               fetchRequest. predicate = NSPredicate (format: "NOT (attribute == value)" )      do {         let searchResults = try appDelegate. getContext (). fetc...

Navigation Bar set for all Devices

Solution:  The below code is used for set the navigation bar title correctly for all devices.         UIBarButtonItem . appearance (). setBackButtonTitlePositionAdjustment ( UIOffsetMake ( 0 , -60 ), for: UIBarMetrics . default )          UINavigationBar . appearance (). tintColor = UIColor . white

Local Notification sound not came when App in foreground iOS Swift

Solution:  If app is in foreground the notification sounds will not be played.So you have to manually play the sound to notify the user.Use the below code to play the sound      var sound: AVAudioPlayer !                         if appstate. applicationState == . active {                             let sound =  "soundname"                              let alertSound = NSURL (fileURLWithPath: Bundle . main . path (forResource: sound, ofType: "mp3" )!)                             do {                                 self . sound = try AVAudioPlayer (contentsOf: alertSound as URL )...

How to create widget or Today extension in iOS Swift

Image
Solution: Step 1:  Select your project then goto Capabilities in that below select app groups and On it.` Step 2: Click the plus icon.It will show one text box.Then enter group.com.companyname.appname. Step 3:After that select the check box to enable Step 4:Goto your iOS app developer account and then enable the app groups in your app in the app dependency section.And then regenerate the certificates and download it and add to your keychain access.Also enter the groups name will be like group.com.companyname.appname. Step 5: Goto editor in the Xcode menu then select Editor->Add Target->search today extension and add it to your project. Step 6: It will generate a folder like whichever you want.Expand that folder.It will had a Viewcontroller. Step 7:  In widget class add the extension like below. class TodayViewController: UIViewController , NCWidgetProviding { } Step 8:  Add the two delegate methods like below.  widgetActiveDi...

Create versioning in CoreData

In Your Xcode select .xcodemodeld file then goto Editor menu in xcode then select Add model version.it will show dialogue box with basic model and current model.select the basic model and then select create. Finally you want to change the active model version.Select the newly created model in left panel and then goto right side first menu then in Model Version segment select your newly created model.Finally it will show green tickmark in the current model version.

Testing GPS in simulator with Fensing

Solution:   It was not possible in simulator with realtime location updates.But you can create a fencing files and test it in a simulator. Goto file->new in your xcode and create a blank file or goto textEdit and create an empty file and save it as filename.gpx and then drag into your xcode. Write code into the file like below. <?xml version= "1.0" ?> <gpx version = "1.1" creator = "Xcode" >     <wpt lat = "43.1257858" lon = "-79.0912399" >         <name> Niagra </name>     </wpt> </gpx> I had named the location name as Niagra with lattitude and longitude. Run your app in the simulator.Goto Debug->Simulate location and selecet your file.Then the simultor location is changed to your mentioned location.

CORDOVA "cannot read property 'variables' of undefined cordova" Error

Problem: Because of Cordova configuration file issues.We cannot able to recover it to build your project.Do the backup of your project before doing the below solution. Solution: It's better to remove the platform and reconfigure it or you can try to go ahead from the initial step to create the project and proceed with that.

CORDOVA "It may be caused by an invalid GOOGLE_APP_ID in GoogleService-Info.plist or set in the customized options" error

Error: Terminating app due to uncaught exception 'com.firebase.core', reason: 'Configuration fails. It may be caused by an invalid GOOGLE_APP_ID in GoogleService-Info.plist or set in the customized options.' Solution: The problem is GoogleService plist configuration fails. Download the  GoogleService-Info.plist from the Http:// console.firebase.google.com and then paste it to the below locations  platforms/ios/<Your Project>/Resources/  and  platforms/ios/<Your Project>/Resources/Resources.

ItunesConnect build Not showing but application loader uploaded with no issues

Image
If you had tried to validate the app in application loader it shows validation success.After that you had tried to upload the app in the app store then it shows no error.If you checked with activity in the itunesconnect it shows processing.After that the build is gone then don't worry. Try the below steps your headache will gone. Goto your app target and click the info tap below the info you had missed to give the photo library usage description or location service access usage description. Give the above descriptions and upload the app into the itunesConnect your headache will gone.. If the above issue is not in your app then goto check with the assets library because if it had issues then also the problem will occur.You must had the 1024 icon set because it must.Also check if any unassigned child in the icon set.

Navigate from one ViewController to other

How to navigate the ViewController from one page to another using NavigationController?         let  nextView = self .storyboard?.instantiateViewController(withIdentifier: "viewidentifier" ) as ! ViewController          self .navigationController?.pushViewController(nextView, animated: true ) The above code will navigate the data to another viewcontroller with navigation stack

CORDOVA Plugin Firebase

Firebase plugin configuration  $ sudo cordova plugin add cordova-plugin-firebase-realtime-database --save The above command will save the firebase plugin inside your project. After that go ahead to the google firebase console and create an app using your bundle identifier (Note:Bundle identifier must be matches otherwise the firebase notification will not works). $ sudo cordova build ios After that goto your project -> Target ->Info -> Url Types It will show additional url type properties. Then paste inside identifier - "REVERSED_CLIENT_ID" and URL schemes as "com.googleusercontent.apps. appidinthefirebaseportal "

CORDOVA Commands for Phongap

Here below are the commands in phonegap for step by step creation and execution of project. Install phone in the Mac: $ sudo npm install -g phonegap@latest It will show some set of command lines for installation. Create new project in Phonegap: $ sudo phonegap create mynewApp The above command will create myApp as an app name and proceed with that.If you want create an app with bundle identifier also the proceed with the below commands. $ sudo phonegap create mynewApp --id "org.companyname.mynewApp" --name "mynewApp" After that enter into the folder and then add the platforms $ cd mynewApp Add the platform: $  cordova platform add ios $ cordova platform add android The above commands are adding the platform in the cordova project Add the plugin $ sudo cordova plugin add pluginName For plugin name we can use the plugin to install and deploy the project Build the project: $  sudo cordova build ios The above command will build th...

How to use the objective c files inside the swift project?

Image
Hai friends , if you confused for using the objective c files already you had but you had developed the app with swift.Then don't worry, apple had already the setup for the migration. Just you can drag and drop the objective c files inside your swift project it says an alert to create a Bridging header.After that you must select the yes then it will create the bridging header. Then you have to open the bridging header file and import the .h files of your objective c files.Then you can clean your project and import the file inside of your swift view controller file. Then you can easily access the variables and functions inside of your swift file.

TableView error Assertion Failiure when try to load the data

Image
When you tried to display the array of values in tableView but you got the below error. Error: Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:] The first thing you have to check with your tableView.Because if you not connected the delegate and data source to the taableView then you got the above error. Also if you did not add the table view data source and table view delegate then the above error will come.So add the delegate and data source things like below. class  ViewController: UIViewController , UITableViewDataSource , UITableViewDelegate { } Data source and delegate methods are connected from ViewController to tableView like below. You must have to implement the required delegate methods inside the View Controller.

CoreData Class used twise Error iOS Swift

Image
When you created coreData and tried to run then if it displays error as "the class name of coreData model className used twice in folder and CoreData".Then try the following steps to solve the issue.Select your coreData model object.Select third option in the right side menu. In above submenu Class->codegen->select as Manual/None. Then rebuild the code.The error is resolved Now.

Keyboard with done button and text field will scroll based on the keyboard height iOS swift

Hai friends, I know you had tired for implementing text field delegate and implement the delegate method codes in all the pages.when you follow the code it's easy to hadle the return button, Done button and more. If you want the keyboard with done button.Also when the keyboard appears when a text field is editing the text field wants to show above the keyboard.Keyboard with the next and previous button.The above three scenarios are fulfilled by using the IQKeyboardManager. First, we want to install the cocoa pods in the system and integrate the IQ keyboard manager. import the IQKeyboard in the app delegate.        import IQKeyboardManagerSwift Inside app delegate adds the below code inside the didfinishlaunchingoptions function. In every text field or textView the keyboard will have done, next, prev buttons and also the when keyboard up then the text field will go up and show the editing.

Location-based data validation when app is in terminated state iOS Swift

Hai friends, I know you had tried for location manager for getting the location updates in the background.But it was not possible from the location manager.In LocationManger we can get the location updates and location based data triggering in the foreground only.If we want to do it in terminated state also we can go with GEOFENCING. We will trigger the functions in terminated state with monitoring the locations using geofencing.

UILocalNotification alarm sound does not trigger when app is in Active state iOS Swift

When the app is in foreground app will not trigger the sound of the notification.It will directly come to the app updates.So you can use the AVPlayer to trigger the sound manually when app receives the notification. Code:     func application( _ application: UIApplication , didReceive notification: UILocalNotification ) {          if application. applicationState == . active { //here play the sound using AVPlayer } }

Navigate Particular ViewController from appdelegate in NavigationViewController stack

When you are in AppDelegate you want to navigate to the particular view in Navigation stack.You will use the window as rootViewController then navigate to the particular ViewController using the navigation stack. Code:                 var rootViewController = self .window!.rootViewController as ! UINavigationController                 rootViewController.pushViewController(ViewController, animated: true )

Create round button in iOS swift

Image
You can create a normal button with width and height as equal.After that in storyboard "show the identity inspector" menu create the runtime attributes. Add the below attributes when clicking the plus button.layer.CornerRadius set the value as number 25.layer.MasksToBounds set the boolean value as true.if the button width and height is 50 then corner radius will be 25 because if you want the circle icon you must set corner half of its width.

GMS map view myLocation button action iOS Swift

In GMS map view when you try with the following.          self . maps . isMyLocationEnabled = true Then it will display myLocation button.When you tap that it will zoom the camera to your current location.But you cannot manually implement the action method.So it is better to manually add the button and set the actions.When you want to display the marker to current location if the user taps on the myLocation button then follow the below code.      var currentmarker = GMSMarker () Above class declare the marker as common.      @IBAction func didTapOnMyLocation( _ sender: Any ) { //This code is used for move the marker to the user based location          if CLLocationCoordinate2DIsValid ( currentmarker . position ) {             currentmarker . position = ( self . maps . myLocation ?. coordinate )!        ...

GMSMarker manually select the marker iOS swift

I know you guys had worked with Google Maps then you had an idea about marker.You can manually call the select marker method to display the selected marker with marker contentWindow.              self . maps . selectedMarker = currentmarker The marker is selected and the info window is opened.

Google Maps get address from latitude and Longitude iOS Swift

If you are implemented the google maps in your application then you can use your core location framework to get the current latitude and Longitude.Then pass the lat and Long to the below function and get the address to the passed lat, long.It will be got from google Places API. Code:     func getAddressForLatLng(latitude: String , longitude: String ) -> String {          let url = NSURL (string: "https://maps.googleapis.com/maps/api/geocode/json?latlng= \ ( latitude ), \ ( longitude )&key= \ ( googlePlacesapiKey )" )         let data = NSData (contentsOf: url! as URL )         if data != nil {         let json = try ! JSONSerialization . jsonObject (with: data! as Data , options: JSONSerialization . ReadingOptions . allowFragments ) as ! NSDictionary             if let result = json[ "results" ] as ? NSArray   { ...

Common Navigation Bar iOS Swift 3

Image
In android, they had Hamburger menu for the common menu.They will use fragment for the menu.But on iOS, we don't have the option.So we will try the below method to achieve that.First, we will create an XIB file for the menu.Then add the menu options in that file.In ViewController add the XIB file as a subview in the top of the view. The above two screenshots had the xib file design and the class file in the second screenshot. The class file as follows Navigation.swift: import UIKit class Navigation: UIView {     @IBOutlet weak var mainTitleLabel: UILabel !     @IBOutlet weak var subTitleLabel: UILabel !     @IBOutlet weak var backBtn: UIButton !     @IBOutlet weak var rightBtn: UIButton !     @IBOutlet weak var addBtn: UIButton !          var callingViewController: AnyObject !     var callingNavigationController: AnyObject !  ...