Ok, so I have already written about why I decided to take the route of building an hybrid(Html5/Native) app, such that I get to know the native environment. So that post also mentions how I have built this Xcode starter project which can serve as a template for building html5 iOS apps using the Ionic framework.  Recently, I wrote about about how my initiative helped someone. and what I have done now is created a branch, Notifications which provides some sample code for adding local notifications to the project. This is a post about Notifications & native HTML5 iOS app where I will talk about what is in the notifications branch of the Github repo.

Questions

1) Why build a Hybrid app such that I need to write some native code?
Well one of the reasons outlined in my previous post, was that I wanted my app to use local notifications. 

2) But scheduling local notifications is so simple, why add some sample code for it?
Yes scheduling local notifications is simple and this tutorial does a good job of showing how to do it. However when I started working on my first iOS app(My Day Todos), it was a little before mid-2014, so Xcode 6 was still in beta and there was not a lot of stuff for Swift out there.

Notifications & native Html5 iOS app

When you run the code from the notifications branch in an iOS simulator or an iOS device, you will be presented with an interface, such as this.

As you can see I am working with a project template generated by using the command ionic start myApp tabs, which at the time generated something like what you see above. Also what you see above is screenshot of the code running in the Xcode simulator that has been rotated to the left. Now lets look at what all those above buttons do and the code that is run when you click on it

Each of the buttons above trigger a function in the Swift based View Controller using the techniques described in this post.

Schedule notifications for test

The purpose of this is just to schedule some local notifications. Clicking that buttons triggers the methods below
private func setTestNotifications(){
var date = NSDate()
//4 calls before this
scheduleNotifications(date.dateByAddingTimeInterval(60), message: "5")
}
private func scheduleNotifications(date: NSDate, message: String) {
let notification:UILocalNotification = UILocalNotification()
notification.fireDate = date
notification.timeZone = NSTimeZone.defaultTimeZone()
notification.fireDate = date
notification.soundName = UILocalNotificationDefaultSoundName
notification.alertBody = message
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}

Cancel all notifications 

So this does exactly what you think it does i.e. it cancels all notifications. However, I do provide a commented out codesnippet in it, should you want to cancel a specific notification. 
private func cancelNotifications(){
UIApplication.sharedApplication().cancelAllLocalNotifications()
/*
below is the code for cancelling specific notifications
for n:AnyObject in UIApplication.sharedApplication().scheduledLocalNotifications {
let not:UILocalNotification = n as UILocalNotification
let alertBody = not.alertBody!
if alertBody == "3" {
UIApplication.sharedApplication().cancelLocalNotification(not)
}
}*/
}

Print notifications to console

Again, this does exactly what you would expect it to do i.e. it prints all the scheduled local notifications.
private func printNotifications(){
for n:AnyObject in UIApplication.sharedApplication().scheduledLocalNotifications {
let not:UILocalNotification = n as UILocalNotification
println("alertBody:(not.alertBody)")
}
}

So what is next?

Well you are welcome to fork this repo, and you can also clone the repo and you can start working with the Notifications branch to get all that which I have outlined in this post.

Get updates?

Other useful tutorials

In addition to this, I have written several iOS tutorials with useful code samples.

Building a native iOS Currency converter app

In this post, I will talk about my approach when building a new iOS Currency Converter. I focus on how I start by defining a simple user story, understand what the user story is followed by how I can accomplish all that technically. This post focuses on the requirements specification to build an iOS mobile app. The concepts discussed here apply to both all mobile apps, this document is focused on iOS Currency Converter. The rest of this document is structured as follows

  • iOS Currency Converter app requirements as mentioned in the assessment document
  • Define the user story for the app
  • A description of what the app will do
  • Technical requirements i.e. what libraries or frameworks can be used to achieve this
  • UI design samples for the minimal UI
  • Some backend architecture design
    • Decisions to adopt this style
  • Lastly, Questions i.e. if any aspect of building this is not clear

You can read more in the link below

Building a native iOS Currency Converter app – My Day To-Do – Bhuman (mydaytodo.com)

Tutorial on animating rows in UITableView

This post is a tutorial on how to add, delete and reload rows in UITableView with animation. Shown below is some code that I wrote for Xcode playground. This code programmatically constructs a UIButton, UITableView, adds them to a view and styles them using auto layout constraints. Then, it randomly generates a number between 1 and 3 and shows how to either,

  1. Animate inserting a new row (UITableViewCell) into a UITableView
  2. How to delete and animate removal of a row (UITableViewCell) from a UITableView
  3. How to animate reloading a section of a UITableViewRow

The code also has the necessary comments that explains some of the things. You can read the full post below.

Xcode Playground to add, delete & reload UITableView rows with animation (How-To) – My Day To-Do (mydaytodo.com)

Build your first iOS app: A Tip Calculator

Ignoring the COVID-19 world we live in right now, going out to eat is something we all love and while we don’t mind tipping the wait staff, we often don’t understand the tip calculation. Hence, I thought that helping you make a tip calculator would be the best way to get you started on making your first iOS app. Don’t worry if you haven’t built anything in iOS prior to this, with the right instructions, it’s not hard. If I can do it, so can you. The rest of this article is structured as follows,

  1. We will talk a little bit about what the app is
  2. Talk about the starter project and Xcode environment
  3. Discuss some storyboard concepts and write some code
  4. Finally, conclude with what you can do next after building this app

You can read the rest of the post in the comment below.

Building your first iOS app – Tip Calculator – My Day To-Do (mydaytodo.com)

Get updates?

If you find any of my posts useful and want to support me, you can buy me a coffee 🙂

https://www.buymeacoffee.com/bhumansoni

Or you can  buying or even try one of my apps on the App Store. 

https://mydaytodo.com/apps/

Also, if you can leave a review on the App Store or Google Play Store, that would help too.

Categories: iOS

0 Comments

Leave a Reply

Verified by MonsterInsights