Posts

Showing posts from April, 2018

Get calories burnt from healthkit information

1. Go to symbols navigator, capabilities and switch on HealthKit. 2. Go to developer.apple.com, create an app ID with your correct bundle id gotten from your app. Indicate that it is an explicit app id and include healthkit in it. 3. Create a provisioning profile - App development - using the new app id created and download it. 4. Open xcode and import profile (sign-in profile). Select the provisioning profile you have just created. 5. Choose the new app id that you have just created. 6. Add the following to info.plist: Privacy – Health Share Usage Description Privacy – Health Update Usage Description 7. In the xcode swift file, import HealthKit This code reads calories burnt and returns true or false depending on whether you are able to be authorised to read the data

Edit constraints for a UI element

Click on the constraints at the side with the mousepad until it is in editing mode. Edit the constraint and press enter.

Asking someone to review your app

You can follow the instructions listed here.

Sharing on Social Media

First, when your app is completed, go to iTunes connect and create a new app. Key in the needed info (remember that your bundle id and sku starts with com.... the one that you use to uniquely identify your app). Go to the bottom and the page and look for 'View your app in App Store'. Click on it to get the URL of your app. Add a button and add an onclick event with the following code: let textToShare = "Join me in getting fit through dance!"                  if let myWebsite = NSURL (string: "https://itunes.apple.com/us/app/daily-dance-fitness/id1372552926?ls=1&mt=8" ) {             let objectsToShare = [textToShare, myWebsite] as [ Any ]             let activityVC = UIActivityViewController (activityItems: objectsToShare, applicationActivities: nil )              activityVC. excludedActivityTypes = [ UIActivityType . airDrop , UIActivityType . addToReadingList ]             activityVC. popoverPresentationController ?. sourceView

How to add admob to your app

First download cocaopods: https://cocoapods.org/app 1. Go to admob and sign up/sign in 2. Click on apps -> IOS 3. Follow instructions 4. Get your admob id Then go to your project folder in desktop in terminal: cd Desktop/nameOfFolder Type: pod init Enter Next, open your pod file inside it, in the target, add: pod 'Google-Mobile-Ads-SDK' Press install When it has been installed, go to terminal and type: pod install --repo-update Next, open your Xcode project and go to the AppDelegate file: import GoogleMobileAds In the application function add: (func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool ) GADMobileAds.configure(withApplicationID: "YOUR_ADMOB_APP_ID") Inside your app itself:   var interstitial: GADInterstitial! //in viewDidLoad:   interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/441146

Playing or pausing a video in web view

webview.evaluateJavaScript("ytplayer.playVideo()") webview.evaluateJavaScript("ytplayer.pauseVideo()") webview.evaluateJavaScript("ytplayer.stopVideo()")

Countdown timer

Create a variable Timer: var timer = Timer() var timeSet = 60 //this means the timer is for 60 seconds Create 2 functions:     @objc func updateTimer() {         self . timeSet -= 1     //This will decrement(count down)the seconds.         if ( self . timeSet == 0 )         {             self . dancewv . reload ()             continuePlaying ()         }     }   func runTimer() {         timer = Timer . scheduledTimer (timeInterval: 1 , target: self ,   selector: ( #selector ( updateTimer )), userInfo: nil , repeats: true )              } In the function where you need the timer to run, call runTimer()

Stop a queue

Above ViewDidLoad: private var workItem: DispatchWorkItem? In ViewDidLoad or where the queue shows: workItem = DispatchWorkItem {                 //actions in the queue                      }         DispatchQueue . main . asyncAfter (deadline: . now (), execute: workItem !) In ViewDidDisappear //if loading web view self.nameOfWebView . stopLoading ()         workItem ?. cancel ()

Starting a new project?

After planning it on paper, Go to Xcode and create a new project, single page. Click on the storyboard on the left side of the screen.  Turn that single page into a navigation page with links. Embed it in a view controller (Editor - embed in Navigation Controller). (see this for details) Set the navigation controller as the initial view controller. You can edit the main title and the colour of the navigation bar using the main navigation controller attribute inspector. Add a bar button link at the top of home page with the words 'HOME'. The other pages will be populated with the back button. Add other view controllers by drag and dropping it back to the screen. Add the UI elements for these view controllers and add missing constraints. Click and drag from the button in the main navigation page to the view controllers they link to. For each view controllers added, go to file->new. Create new Cocoa Touch file for each view controller and give it a name. Click on