Log on "my app" using home screen passcode or touchid - iphone

Is it possible to have the lock screen pin/touchid to also authenticate my application if this is protected the same way using a pin/touchid? So I dont have to do this twice when opening an actionable notification.

Yes you can use home screen Passcode or TouchID to authenticate the app with in timeInterval by setting a property touchIDAuthenticationAllowableReuseDuration which is newly introduce in LocalAuthentication Framework in iOS9.
Code snippet(Example):-
let laContext = LAContext()
let timeInterval = 10 // In Seconds
LAContext.touchIDAuthenticationAllowableReuseDuration = timeInterval
......
......
If the device was successfully unlocked by TouchID/Passcode within this time interval, then Touch ID authentication on this context will succeed automatically and the reply block will be called without prompting user for Touch ID Authentication.
Note:- The Maximum supported interval is 5 minutes and setting the value beyond 5 minutes does not increase the accepted interval.

Related

Observable is not working when app is running in background in ionic?

When I do Login I am starting to check observable working but when application is in background it is not executing. I am using observable because after every 5 seconds refresh should happen. It seems it is not running in background. Any other solution to run the code after every 1 minute whether application is in background or foreground. Thanks in advance !
Loginsuccessfully
this.provider.startBackgroundRefreshInterval();
In service class below code added
startBackgroundRefreshInterval() {
var refreshInterval = localStore.getPersistedData(App.ISCHECKBOX_KEY);
this.timerSubscription = Observable.interval(parseInt(refreshInterval))
.subscribe((val) => {
console.log("Observable subscribed");
});
}
/**
* unsubscribe subscription
*/
unSubscribeOnehourSubscription() {
console.log("Observable Unsubscribed");
this.timerOneHourSubscription.unsubscribe();
}
Now refreshInterval is based on checkbox value selection
updateCheckboxList(value:any) {
this.service.unSubscribeSubscription();
this.service.startBackgroundRefreshInterval();
}
Once application will go in background Observable not calling
currently refreshInterval selected as 1 minute
what is other way to call functon continuosly in background in ionic ?
I am currently working on the same thing. While I can't say I know all the things about this, here is what I have found so far.
When your app goes to the background, it is essentially put to sleep. Meaning none of the code you are counting on, including intervals is going to execute.
Here are some solutions to this problem I have worked on.
1) BackgroundFetch as seen here in this cordova plugin https://github.com/transistorsoft/cordova-plugin-background-fetch and https://ionicframework.com/docs/native/background-fetch will in both android and ios attempt to run a callback every approximately 15 minutes (read the link for why that timing is a thing).
2) BackgroundMode as seen here https://ionicframework.com/docs/native/background-mode will put your app into a "stay active while in background" mode that you can control. This will work in keeping your app up and running even in background, but you may find that this is not acceptable to the stores (particularly might get rejected by ios store).
That's what I've found thus far. Hope it's helpful.

Location update Background task been terminated after 3 minutes, if no permission is granted. how can we extend that?

I am trying to Fetch user location at Predefined Time Interval (i.e. 30 Minutes), I have enabled location update in background modes, For testing purpose I am creating local notification every time when location is been detected.if internet is available and location permission is granted then everything works fine but if no location permission then after 3 minutes app is been terminated in background.
I have Used Following approach, please do let me know if I have missed anything ?
1)I have also created background task and invalidate background task at every 150 Seconds or less seconds. In Restart Method Location manager is
func beginNewBackgroundTask()
{
var previousTaskId = currentBgTaskId;
currentBgTaskId = UIApplication.shared.beginBackgroundTask(expirationHandler:
{
})
if let taskId = previousTaskId{
UIApplication.shared.endBackgroundTask(taskId)
previousTaskId = UIBackgroundTaskInvalid
}
timer = Timer.scheduledTimer(timeInterval: BackgroundLocationManager.BACKGROUND_TIMER, target: self, selector: #selector(self.restart),userInfo: nil, repeats: false)
}
2)In Restart Method I am calling update location method, if permission is already been granted.and if Permission is not granted then I will call initiate background task method again to keep app running, and send user notification.
func restart ()
{
if(CLLocationManager.authorizationStatus() == CLAuthorizationStatus.restricted || CLLocationManager.authorizationStatus() == CLAuthorizationStatus.denied )
{
self. beginNewBackgroundTask()
self.scheduleNotification(Message:”Please enable Location”)
}
else
{
locationManager.startUpdatingLocation()
}
}
If app has no permission of location then new background task is not being created and app will be terminated in background after 3 minutes.
Can we keep app running in background if there is no permission for location ?
Strange Thing if app is in debug mode (Attached with mac) then notification is been generated for 8 - 9 Minutes, but without debug mode only3 Minutes did I miss something ? Or we can not keep app running in background more then 3 minutes if there is no permission for location

Using NSLocalNotification for multiple reminders

I am creating a reminder based app and my only problem right now is being able to implement reminders on my app.
Basically the user is presented with a UITableView where the user can add events and I'd like to fire these dates with a notification to the user reminding them of the event on a date saved to Core Data.
At this time, I still do not understand how NSLocalNotification works an I have heard some users here say how apple only allows 64 notifications to be processed at a time and I only managed to create 1 but when creating another event, It is down to 0 and randomly goes back to 1 event when I debug my app with the
UIApplication.sharedApplication().scheduledLocalNotifications?
and I can see the notification I set but not the other ones.
Any sample app in swift would greatly help me understand how I can set multiple notifications to add, edit, delete them.
Thanks in advance and happy coding
The easiest way to tackle this is to just create notifications and schedule them. If you want to remove specific notifications you will have to hold on to their references and persist them across app launches, however you can always remove all the currently scheduled notifications with UIApplication.sharedApplication().cancelAllLocalNotifications()
This is an example of scheduling a notification to fire once a day at the same time for 5 days:
let secondsInADay = 60 * 60 * 24
for i in 1...5 {
var dayString = "\(i) days"
if i == 1 {
dayString = "\(i) day"
}
let notification = UILocalNotification()
notification.fireDate = NSDate(timeInterval: Double(i * secondsInADay), sinceDate: NSDate())
notification.alertBody = "It has been \(dayString) since you last opened the app."
notification.soundName = UILocalNotificationDefaultSoundName
if notification.fireDate?.timeIntervalSinceNow > 0 {
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
}
Also, you are correct, each app is given a queue for local notifications that have yet to fire. That queue can hold 64 individual notifications (a repeating notification counts as only 1 of those 64).

Check a web page periodically in background

I need to check periodically a web page.
My idea is to set a local notification periodically, for example every 20 minutes. When notification leaves, device should load the web page, check a condition and if the condition is true, device should rang, otherwise nothing.
(NOTIFICATION) -> (LOAD WEB PAGE) -> [VERIFY CONDITION]-|if true|-> (RING)
Is this technically possible to do? How can I load a web page while app isn't running?
My sketch of code was like this:
func check () {
pageCode = // find a way to load the page
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(NSEC_PER_MSEC * 100))
dispatch_after(delayTime, dispatch_get_main_queue()){
let readCode = self.pageCode.stringByEvaluatingJavaScriptFromString("document.getElementsByTagName('body')[0].outerHTML")
if letturaCodice?.containsString("Some text") == true {
ringPhone()
}
}
}
Not possible using UILocalNotification, you could do it with a remote notification though.
Apple has a guide here: See - "Using Push Notifications to Initiate a Download"
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
A remote notification platform I've used before is called OneSignal, it's completely free and allows you to schedule notifications. https://onesignal.com
Edit:
Doesn't answer question about ringing, not sure about that bit sorry!
Option 1:
You could build the app to use background app refresh function that you could cause an alert if lets say you do not get an http status code of 200.
If you use this option you could build in the function to have a custom tone to play that you build into the app.
Option 2:
Use a server side script todo the checking and have it fire off a push notification. This method would depend on phone settings as to how the notification would function.
You can try to use Grand Central Dispatch to run a background process and inside it add notification observer.
UPD: Like this:
dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0)) {
() -> Void in
// catch notifications here
}

Auto Log out from an iPhone app (when app goes in the background)

The Settings bundle of my iPhone has the user login and password credentials saved.(similar to the Mail app). The application in its current state does not have a separate login/password view page.
Now, when the app enters the background, I would want it to wait for 40 seconds and after that automatically log off. I found similar posts, and thus found that I could use the methods in the app delegate:
- (void) applicationDidEnterBackground:(UIApplication *)application
{
currentTimeBackground = CACurrentMediaTime();
}
- (void) applicationDidBecomeActive:(UIApplication *)application
{
currentTimeActive = CACurrentMediaTime();
}
Then I plan to use the bottom logic somewhere in my code to trigger a logout.
if ((currentTimeActive - currentTimeBackground)> 40 ) {
NSLog(#"Need to prompt for re login!");
// Logic to logout the application.
}
Now, I found that it is not possible to alter the Settings bundle (.plist) file through a program (at run time). (http://stackoverflow.com/questions/4921890/how-can-i-modify-a-settings-bundle-in-real-time)
So please suggest me how would I log out of this application?
This application fetches data from a server (I have a local server set up for development).
Create a background task and have it wait 40 seconds and then log off. If the user re-opens the app, cancel the background task.