UILocalNotification in Swift - ios

My app uses UILocalNotification. On some action from a user, say press of a button, I need to cancel ALL UILocalNotifications, which were set by my application. I have found a solution, however this didn't work out in all cases. The solution was like this:
let scheduledNotifications = UIApplication.shared.scheduledLocalNotifications
scheduledNotifications?.forEach {
UIApplication.shared.cancelLocalNotification($0)
}
Trying to fix the bug (one or several notifications were not cancelled), I've found a shorter solution, which was simply this:
UIApplication.shared.cancelAllLocalNotifications()
The latter one seems to work just fine.
What don't I understand? Is there really some difference in functionality of these two snippets of code?
Accompanying question:
1) Specifically, notification set by another version of the app was not cancelled by the first solution.
2) What is happening on rolling out a new version of app? I mean, what about UserDefaults and LocalNotifications set by previous version of the app? Are these kept between different version of the app? What happens with the app on update from App Store?
Any help is appreciated. Thank you!

Related

Create a guide (tutorial) for my ios app

I am creating swift app and I would like to create some tutorial to it(or something that will show how my app works). I have found only this question Creating a tutorial for my iOS app with page control , but it is in objective-c. So my question is: How can I create a tutorial for my ios app , or if you know some page in swift where can I read something about it. Thank you.
You can implement this yourself by adding the view(s) and controller(s) as usual and add NSUserDefaults to check whether the user is starting the app for the first time or not. If not, you can trigger a segue to your normal Home-ViewController.
Alternatively, you can use one something similar to these:
https://github.com/ariok/BWWalkthrough
https://github.com/Athlee/OnboardingKit

iOS Show UIAlert in Safari when using My App's Share Extension

I'm developing a simple content blocker for iOS 9+ devices. Everything seems to be working fine in terms of blocking ad's / trackers etc and I even have the ability to 'whitelist' websites directly from Safari using a Share Extension Action.
My question is when the user taps Action > My Apps Share Extension [which adds it to a list inside the main app] I want to show a simple Alert that says something like 'This site has been added to your whitelist..." for a few seconds and then disappear.
... how do I do this?
**UPDATE I have read all of Apples documentation on this but still can't figure it out. The post here does actually refer to how to design a streamlined UI but doesn't really cover my situation.
Hoping someone will know :-)
Why you don't use Notifications for this , you can have your notification style set to show like an UIAlert. You can see something like that in Calendar app in iOS.
UPDATE:
I did a little bit more digging , it's not possible to change the style programmatically according to this. So the best choice is handling it when your app is in foreground. I can't think of any other OS wide solution other than local notifications.

How to implement a running clock in iOS?

I am trying to make a simple app whereby a user selects a date/time in future and upon that date/time happening that a particular event happens.
How do I get about getting such a thing implemented?
Thanks
You want UILocalNotification.
Are you talking about getting Notification such as Alarm??
If yes, Local Notification is the same that you want. For using it please go through demo explanation : http://www.iostipsandtricks.com/ios-local-notifications-tutorial/
and for API's see YusufX's answer...

Shake iPhone to open my app. Possible?

Is it possible to shake the iphone when the home screen is displayed and make my app open?
for eg : triggering
(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event to open my app. Is it possible in ios5 using public sdk?
I am more interested in the technical aspects than the usability so please, if you think that's a horrible idea or you want to ask me what would I do such a thing, then I would say thanks but I understand that!
I dont want to hack into OS, use a jailbroken phone...but more curious to know can an app in itself have the complete logic to achieve the same?
EDIT
I accepted the answer "not possible" but then got another answer/comment from #skippy saying it might be possibel so I am going back to figuring it out mode. Will update accepted answer accordingly!
This is not possible. Even if it was its not a good idea, think about what would happen if two apps could do this...
Unfortunately no. You can handle shake-style events only when your application is already running.
I think it's possible, but complicated.
The first app run in background (read about required background modes).
This app must call the second app in case of shake.
It's strange behaviour, read about:
Launch an app from within another

Calling a number on the iPhone

So,
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:#"tel: 14165551212"]];
calls a phone number on the iPhone.
What other things can we do, though? I'm trying to make a simple app that has a list of phone numbers. It dials the first one in that list, and re-dials if it is engaged. Is this possible?
You can certainly open a link in Safari. It should also be possible to go to the Mail app and create an email. I heard that you can also go to the Messages app.
And, I don't think that what you described is possible. Your app can't do much from the background. And I'm pretty sure that it can't control/monitor any other apps(including Phone), so it will not be possible to re-dial it.
Hope it helps
What you are describing is partially possible starting with iOS 4.0 and even better with iOS 5. You may initiate dialling a number from your app with telprompt URL schema and when iOS finishes with the call it will open your app again, see Stackoverflow answer
What is problematic is getting the result of the call: whether it was successful or engaged, etc. You may want to have a look at CTCallCenter class reference.

Resources