Unlock Content based on Day (iOS App with Xcode)
up vote
0
down vote
favorite
I am trying to get create an app where you can unlock a certain picture every day throughout the month of December, like an advent calendar.
So if the user is pressing the button for a certain day (all days have a button with their date on) the app shall compare the current date on the device to the unlock date. For example:
If the user is pressing the button for the 01.12.18 (dd.MM.yy) and it currently ist that day or any day later it shall display picture number one.
Else: (if the day isn't reached yet) the user shall see another picture, that says sth. like "You're too early! Please wait some more."
Any suggestions or example codes are very appreciated!
The prototype of the code looks like this:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBOutlet weak var dailyContent: UIImageView!
@IBAction func türchen1Button(_ sender: Any) {
// if 01.12.18 (dd.MM.yy) is today or past today
// dailyContent.image = picture1
//
// else if 01.12.18 (dd.MM.yy) is in the future
// dailyContent.image = pictureTooEarly
}
}
This app shall be a present for my girlfriend and I appreciate every help!
Thank you in advance!
Benjamin
ios swift4 xcode10
add a comment |
up vote
0
down vote
favorite
I am trying to get create an app where you can unlock a certain picture every day throughout the month of December, like an advent calendar.
So if the user is pressing the button for a certain day (all days have a button with their date on) the app shall compare the current date on the device to the unlock date. For example:
If the user is pressing the button for the 01.12.18 (dd.MM.yy) and it currently ist that day or any day later it shall display picture number one.
Else: (if the day isn't reached yet) the user shall see another picture, that says sth. like "You're too early! Please wait some more."
Any suggestions or example codes are very appreciated!
The prototype of the code looks like this:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBOutlet weak var dailyContent: UIImageView!
@IBAction func türchen1Button(_ sender: Any) {
// if 01.12.18 (dd.MM.yy) is today or past today
// dailyContent.image = picture1
//
// else if 01.12.18 (dd.MM.yy) is in the future
// dailyContent.image = pictureTooEarly
}
}
This app shall be a present for my girlfriend and I appreciate every help!
Thank you in advance!
Benjamin
ios swift4 xcode10
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to get create an app where you can unlock a certain picture every day throughout the month of December, like an advent calendar.
So if the user is pressing the button for a certain day (all days have a button with their date on) the app shall compare the current date on the device to the unlock date. For example:
If the user is pressing the button for the 01.12.18 (dd.MM.yy) and it currently ist that day or any day later it shall display picture number one.
Else: (if the day isn't reached yet) the user shall see another picture, that says sth. like "You're too early! Please wait some more."
Any suggestions or example codes are very appreciated!
The prototype of the code looks like this:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBOutlet weak var dailyContent: UIImageView!
@IBAction func türchen1Button(_ sender: Any) {
// if 01.12.18 (dd.MM.yy) is today or past today
// dailyContent.image = picture1
//
// else if 01.12.18 (dd.MM.yy) is in the future
// dailyContent.image = pictureTooEarly
}
}
This app shall be a present for my girlfriend and I appreciate every help!
Thank you in advance!
Benjamin
ios swift4 xcode10
I am trying to get create an app where you can unlock a certain picture every day throughout the month of December, like an advent calendar.
So if the user is pressing the button for a certain day (all days have a button with their date on) the app shall compare the current date on the device to the unlock date. For example:
If the user is pressing the button for the 01.12.18 (dd.MM.yy) and it currently ist that day or any day later it shall display picture number one.
Else: (if the day isn't reached yet) the user shall see another picture, that says sth. like "You're too early! Please wait some more."
Any suggestions or example codes are very appreciated!
The prototype of the code looks like this:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBOutlet weak var dailyContent: UIImageView!
@IBAction func türchen1Button(_ sender: Any) {
// if 01.12.18 (dd.MM.yy) is today or past today
// dailyContent.image = picture1
//
// else if 01.12.18 (dd.MM.yy) is in the future
// dailyContent.image = pictureTooEarly
}
}
This app shall be a present for my girlfriend and I appreciate every help!
Thank you in advance!
Benjamin
ios swift4 xcode10
ios swift4 xcode10
asked Nov 19 at 17:24
Benjamin H.
53
53
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
- Assign the tags 1 - 24 to the buttons which represent the days.
Use one
IBAction
and connect all buttons to this action.
@IBAction func türchenButton(_ sender: UIButton) {
In the body of the action get the current year and create a date of the corresponding button and check if the date is in the future
let now = Date()
let calendar = Calendar.current
let currentYear = calendar.component(.year, from: now)
let türchenComponents = DateComponents(year: currentYear, month: 12, day: sender.tag)
let türchenDay = calendar.date(from: türchenComponents)!
if calendar.compare(türchenDay, to: now, toGranularity: .day) == .orderedDescending {
// is in the future
dailyContent.image = pictureTooEarly
} else {
// is today or past today
dailyContent.image = picture1
}
}
We should get the date from internet/server, Otherwise, by changing phone DateTime content get unlocked. Thoughts @vadian?
– Satish
Nov 19 at 18:35
@Satish Parse worldclockapi.com/api/json/utc/now to get the current date online.
– vadian
Nov 19 at 18:55
Thank you very much for your help! it worked out just the way I wanted it to work :) But one question: When we will be in 2019, will the content still be viewable, or will it be crashing then?
– Benjamin H.
Nov 19 at 19:53
It works in every year because thecurrentYear
is retrieved separately.
– vadian
Nov 19 at 19:56
The code is supposed to work. Check if the tags are assigned correctly. For example printsender.tag
– vadian
Nov 28 at 21:47
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
- Assign the tags 1 - 24 to the buttons which represent the days.
Use one
IBAction
and connect all buttons to this action.
@IBAction func türchenButton(_ sender: UIButton) {
In the body of the action get the current year and create a date of the corresponding button and check if the date is in the future
let now = Date()
let calendar = Calendar.current
let currentYear = calendar.component(.year, from: now)
let türchenComponents = DateComponents(year: currentYear, month: 12, day: sender.tag)
let türchenDay = calendar.date(from: türchenComponents)!
if calendar.compare(türchenDay, to: now, toGranularity: .day) == .orderedDescending {
// is in the future
dailyContent.image = pictureTooEarly
} else {
// is today or past today
dailyContent.image = picture1
}
}
We should get the date from internet/server, Otherwise, by changing phone DateTime content get unlocked. Thoughts @vadian?
– Satish
Nov 19 at 18:35
@Satish Parse worldclockapi.com/api/json/utc/now to get the current date online.
– vadian
Nov 19 at 18:55
Thank you very much for your help! it worked out just the way I wanted it to work :) But one question: When we will be in 2019, will the content still be viewable, or will it be crashing then?
– Benjamin H.
Nov 19 at 19:53
It works in every year because thecurrentYear
is retrieved separately.
– vadian
Nov 19 at 19:56
The code is supposed to work. Check if the tags are assigned correctly. For example printsender.tag
– vadian
Nov 28 at 21:47
add a comment |
up vote
0
down vote
accepted
- Assign the tags 1 - 24 to the buttons which represent the days.
Use one
IBAction
and connect all buttons to this action.
@IBAction func türchenButton(_ sender: UIButton) {
In the body of the action get the current year and create a date of the corresponding button and check if the date is in the future
let now = Date()
let calendar = Calendar.current
let currentYear = calendar.component(.year, from: now)
let türchenComponents = DateComponents(year: currentYear, month: 12, day: sender.tag)
let türchenDay = calendar.date(from: türchenComponents)!
if calendar.compare(türchenDay, to: now, toGranularity: .day) == .orderedDescending {
// is in the future
dailyContent.image = pictureTooEarly
} else {
// is today or past today
dailyContent.image = picture1
}
}
We should get the date from internet/server, Otherwise, by changing phone DateTime content get unlocked. Thoughts @vadian?
– Satish
Nov 19 at 18:35
@Satish Parse worldclockapi.com/api/json/utc/now to get the current date online.
– vadian
Nov 19 at 18:55
Thank you very much for your help! it worked out just the way I wanted it to work :) But one question: When we will be in 2019, will the content still be viewable, or will it be crashing then?
– Benjamin H.
Nov 19 at 19:53
It works in every year because thecurrentYear
is retrieved separately.
– vadian
Nov 19 at 19:56
The code is supposed to work. Check if the tags are assigned correctly. For example printsender.tag
– vadian
Nov 28 at 21:47
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
- Assign the tags 1 - 24 to the buttons which represent the days.
Use one
IBAction
and connect all buttons to this action.
@IBAction func türchenButton(_ sender: UIButton) {
In the body of the action get the current year and create a date of the corresponding button and check if the date is in the future
let now = Date()
let calendar = Calendar.current
let currentYear = calendar.component(.year, from: now)
let türchenComponents = DateComponents(year: currentYear, month: 12, day: sender.tag)
let türchenDay = calendar.date(from: türchenComponents)!
if calendar.compare(türchenDay, to: now, toGranularity: .day) == .orderedDescending {
// is in the future
dailyContent.image = pictureTooEarly
} else {
// is today or past today
dailyContent.image = picture1
}
}
- Assign the tags 1 - 24 to the buttons which represent the days.
Use one
IBAction
and connect all buttons to this action.
@IBAction func türchenButton(_ sender: UIButton) {
In the body of the action get the current year and create a date of the corresponding button and check if the date is in the future
let now = Date()
let calendar = Calendar.current
let currentYear = calendar.component(.year, from: now)
let türchenComponents = DateComponents(year: currentYear, month: 12, day: sender.tag)
let türchenDay = calendar.date(from: türchenComponents)!
if calendar.compare(türchenDay, to: now, toGranularity: .day) == .orderedDescending {
// is in the future
dailyContent.image = pictureTooEarly
} else {
// is today or past today
dailyContent.image = picture1
}
}
answered Nov 19 at 17:50
vadian
140k13146165
140k13146165
We should get the date from internet/server, Otherwise, by changing phone DateTime content get unlocked. Thoughts @vadian?
– Satish
Nov 19 at 18:35
@Satish Parse worldclockapi.com/api/json/utc/now to get the current date online.
– vadian
Nov 19 at 18:55
Thank you very much for your help! it worked out just the way I wanted it to work :) But one question: When we will be in 2019, will the content still be viewable, or will it be crashing then?
– Benjamin H.
Nov 19 at 19:53
It works in every year because thecurrentYear
is retrieved separately.
– vadian
Nov 19 at 19:56
The code is supposed to work. Check if the tags are assigned correctly. For example printsender.tag
– vadian
Nov 28 at 21:47
add a comment |
We should get the date from internet/server, Otherwise, by changing phone DateTime content get unlocked. Thoughts @vadian?
– Satish
Nov 19 at 18:35
@Satish Parse worldclockapi.com/api/json/utc/now to get the current date online.
– vadian
Nov 19 at 18:55
Thank you very much for your help! it worked out just the way I wanted it to work :) But one question: When we will be in 2019, will the content still be viewable, or will it be crashing then?
– Benjamin H.
Nov 19 at 19:53
It works in every year because thecurrentYear
is retrieved separately.
– vadian
Nov 19 at 19:56
The code is supposed to work. Check if the tags are assigned correctly. For example printsender.tag
– vadian
Nov 28 at 21:47
We should get the date from internet/server, Otherwise, by changing phone DateTime content get unlocked. Thoughts @vadian?
– Satish
Nov 19 at 18:35
We should get the date from internet/server, Otherwise, by changing phone DateTime content get unlocked. Thoughts @vadian?
– Satish
Nov 19 at 18:35
@Satish Parse worldclockapi.com/api/json/utc/now to get the current date online.
– vadian
Nov 19 at 18:55
@Satish Parse worldclockapi.com/api/json/utc/now to get the current date online.
– vadian
Nov 19 at 18:55
Thank you very much for your help! it worked out just the way I wanted it to work :) But one question: When we will be in 2019, will the content still be viewable, or will it be crashing then?
– Benjamin H.
Nov 19 at 19:53
Thank you very much for your help! it worked out just the way I wanted it to work :) But one question: When we will be in 2019, will the content still be viewable, or will it be crashing then?
– Benjamin H.
Nov 19 at 19:53
It works in every year because the
currentYear
is retrieved separately.– vadian
Nov 19 at 19:56
It works in every year because the
currentYear
is retrieved separately.– vadian
Nov 19 at 19:56
The code is supposed to work. Check if the tags are assigned correctly. For example print
sender.tag
– vadian
Nov 28 at 21:47
The code is supposed to work. Check if the tags are assigned correctly. For example print
sender.tag
– vadian
Nov 28 at 21:47
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379760%2funlock-content-based-on-day-ios-app-with-xcode%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown