iOS long vibration - ios

I have an application that can detect accidents, it is really important for us to alert users using vibration and alert sound if an accident is detected.
My questions are:
Is it possible to add long vibration in application by using custom sounds or something that apple might be ok with?
If I use private apis, is it possible to convince apple to approve my app considering that the use case is really critical?

Two questions here, really.
1st one: haptic feedback / control vibration on iOS / custom iOS patterns
No, it can't be done, even in the new Apple Watch without Jailbreaking your phone. You can have a look at this keyboard mod (needs Jailbreak). Here you have some code but it needs Jailbreaking your phone.
If you need to alert your users I recommend just playing the default vibration inside a while. Sleep the current thread for 1 sec, then vibrate again until some boolean flag changes. Objective-C Pseudocode:
while (!endVibrationAlert) {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
[NSThread sleepForTimeInterval:1];
}
// when user touches some button to dismiss alert
self.endVibrationAlert = true;
2nd one: never ever try to bypass Apple's reviewing system. Abide by the rules. For your 1st version, maybe it passes. Then, in the next update your App can get rejected.

Related

Open iOS (Flutter) app directly after answering VoIP call from locked iOS device

A project I'm working on works mainly around a good UI/UX. The one issue I'm facing is answering calls on a locked iOS device.
Documentation:
Apple introduced the CallKit and PushKit features to allow access to the native call screen which is good, but not ideal in my case.
There is good literature on both of these components, e.g.
Receiving incoming calls
Responding to VoIP Notifications from PushKit
Very useful iOS 13 PushKit restrictions
Previously asked?
There are many questions about this issue, mostly centered around 2 years ago, which is why I am asking again.
Recommended with tutorials - Lock Screen UI with incoming Call
iOS - Can I open my VoIP app on answering call using Callkit
CallKit: Launch app when screen is locked
https://github.com/react-native-webrtc/react-native-callkeep/issues/319#issuecomment-758628836
Some extra CallKit/PushKit tutorials
https://www.nikola-breznjak.com/blog/ios/create-native-ios-app-can-receive-voip-push-notifications/
(Flutter Specific, can be used for native iOS too) https://github.com/masashi-sutou/flutter_ios_webrtc_kit
https://www.raywenderlich.com/1276414-callkit-tutorial-for-ios
https://agostini.tech/2019/06/23/receiving-incoming-calls-with-pushkit/
https://learn.vonage.com/blog/2021/01/28/handling-voip-push-notifications-with-callkit/
https://medium.com/#ykawanabe/system-calling-screen-with-callkit-77004b1224e5
The issue is non of these, as far as I have read, provide a mechanism to open an app directly after answering.
Viable solutions
The only way to do this with the current implementation is to use the last of the 6 buttons on the CallKit screen (optionally with an AppIcon), see image [Masked Image Icon]:
Examples:
GitHub example with App Icon & custom ring sound
Question:
I can't find any solution to open my iOS (Flutter app) when answering a VoIP call from a locked state - is this at all possible?
I don't know if you still need the solution, but for the sake of others finding this question: I found the answer in another Stackoverflow post.
Link: iOS CallKit. Jump directly to application
I am copying the answer here for clarity (credits go to 0awawa0) Note that the code example is in Swift.
So apparently, if you set. hasVideo property to true for your
CXCallUpdate when reporting the call, system will automatically open
your application when call is accepted. Anyway, this feature is not
mentioned anywhere in the documentation. Or, at least, I can not find
anything about it.
Here is the part of my code that reports new call now:
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .generic, value: handle)
update.hasVideo = true // <- was false earlier, setting to true did the trick
update.supportsDTMF = false
update.supportsHolding = true
update.supportsGrouping = false
update.supportsUngrouping = false
callProvider.reportNewIncomingCall(with: uuid, update: update, completion { error in /*...*/ }

How know if iOS device is sleeping in a background process

I have a application running in background and I need to know if device is sleeping in order to start a sincronisation process, but I didn't find information about this.
Does anyone know if it is posible and how do it?
Thanks.
You cannot know if the device is asleep because you have no control over the OS.
You can, otherwise, use the App Delegate method:
- (void)applicationWillResignActive:(UIApplication *)application
{
//your code goes here
}
if you want to wait till your app goes to background
I believe you can't do this using public API. The only thing which you can check whether your application is active or in background (using AppDelegate callbacks). And as Luke pointed out in comments, checking whether device "falls asleep" isn't iOS best design practice.
There are some private API's to do what you want, you can look at following questions:
Is there a way to check if the iOS device is locked/unlocked?
Detect screen on/off from iOS service
However, you should be aware that your app won't be accepted in AppStore in such case.

Close the app in 'applicationDidEnterBackground'

I have an iOS app and for several reasons I need to close it when the user clicks the home button of the device. I can't support background.
I now there is an option called Application does not run in background, but I can't use it because there is a bug from Facebook sdk that makes impossible to authenticate with Facebook when this option is in use. Here is the bug report at Facebook.
So I don't know what to do, how can I restart it? An [[NSThread mainThread] exit] in applicationDidEnterBackground?
Is there a workaround for this?
The legal (Apple will approve the app) way is set or create the key UIApplicationExitsOnSuspend to YES in the Info.plist.
To get this as action you would need exit(0) or [[NSThread mainThread] exit], but this is against the Human Interface Guidelines from Apple
So what you could also do is just design all your views in a manner that they have a reset function . Then when applicationDidEnterBackground store that you need to reset on next startup or directly call reset on all active views in applicationWillEnterBackground
So your App didn't really restart, but all your views look like this. To give you an advice, I would design my app in a manner that it doesn't shutdown itself when i quit. This is no good user experience.. Once clicked the home button and all your data is away, same when you receive a call.
Plain old stdlib.h exit() will terminate the app, though it violates apple guidelines (see "Don't Quit Programmatically").
Your app won't perform any background actions if you don't initiate any.

Exit an application or Go to Dash board(main page) programmatically - IOS

I want to exit my application programatically, I googled, some people suggesting to use exit(1), but apple is not supporting that I guess. If it is the case, How do I exit my application programatically. Any helps appreciated.
exit(0); will work but don't use it
You shouldn't force close an app as the standard way to terminate an application is to press the home button (or use the multitasking bar)
Don’t Quit Programmatically
Never quit an iOS application programmatically because people tend to
interpret this as a crash. However, if external circumstances prevent
your application from functioning as intended, you need to tell your
users about the situation and explain what they can do about it.
Depending on how severe the application malfunction is, you have two
choices.
Display an attractive screen that describes the problem and suggests a
correction. A screen provides feedback that reassures users that
there’s nothing wrong with your application. It puts users in control,
letting them decide whether they want to take corrective action and
continue using your application or press the Home button and open a
different application
If only some of your application's features are not working, display
either a screen or an alert when people activate the feature. Display
the alert only when people try to access the feature that isn’t
functioning.
Source
I believe u are not reading the comment properly thus posting the answer for ur question here:
"Simply Don't do that. as apple does not allow application to crash like that."
look at here. How do I exit my iOS app gracefully after handling a Local Notification and here Exit application in iOS 4.0 there are fare discussion over here.
After the release of iOS4, multitasking(new feature) was added by APPLE. This feature enabled the users to keep the app into suspended state in the background if in between he has to do some other activity(e.g. picking up phone call). So Apple considers your app should be maintained in the background until the user deletes the application from the background. And after this if you want to exit use exit(0);, using this would further lead to rejection from AppStore
Here's a wrong way to accomplished exit function in your app. This is coming to mind when I read your question, never applied anywhere, so be careful if you'll gonna implement this!
- (void) exitApp
{
NSArray *array = [[[NSArray alloc] init] autorelease];
NSLog(#"%#",[array objectAtIndex:10]); //will crash here, looks like exit.
}
P.S. You can put this code inside your UIAlertView asking exit confirmation like Do you really want to exit?. In YES button pressed you can call [self exitApp]; User think that he'll exit from the app.

force application to terminate in iPhone

I am developing an iPhone application which is completely based on web data.
If it is not connected to the internet, the application is of no use.
So, I want to terminate the application when connection is not found.
NSURL *tmpURl=[NSURL URLWithString:[NSString stringWithFormat:#"%#search.php",[iGolfAppDelegate getServerPath]]];
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:tmpURl];
con=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(con){
myWebData=[[NSMutableData data] retain];
} else {
//Yes I will provide two buttons on alertview "retry" & "close", & when user
//taps on "close" => application should terminate.
// i will send alertview & when user taps on button close then
// what to write for terminating application?
// Ok Ok. Don't terminate. User will terminate.
// user is owner of iPhone
// let him choose what to do
// wait till wifi connects
}
The question is how to terminate the application?
Is exit(0) only the option for terminating application or is there any other option available?
Apple is is absolutely clear about this topic:
There is no API provided for
gracefully terminating an iPhone
application. Under the iPhone OS, the
user presses the Home button to close
applications. Should your application
have conditions in which it cannot
provide its intended function, the
recommended approach is to display an
alert for the user that indicates the
nature of the problem and possible
actions the user could take - turning
on WiFi, enabling Location Services,
etc. Allow the user to terminate the
application at their own discretion.
See Technical Q&A QA1561
You might consider informing the user that they cannot use your application without an active network connection. Just terminating the application outright seems like a very unfriendly way of doing this; the user will simply see the app "disappear".
Every well-behaved app I've seen will at least give a notification before terminating.
I would advise you to reconsider for 3 reasons
It may appear that your app crashed.
The user may get an internet connection while your app is up. In this case a 'Retry' would be best.
I think Apple may actually not accept the app if it does that. It is for sure not what they would do if an Apple application needed an internet connection, and they do test to see what an app will do without a connection.
If (for whatever reason)you do want to do it you can use.
exit(0);
You could always just divide by zero. As a bonus, the implementation would reflect what a good idea this is.
Hope this helpful
[[NSThread mainThread] exit];
If you terminate it will look like your app has crashed!
Best to put up a message saying that there is no internet connection and give them an option to retry (in case they can get an internet connection), or choose to quite it themselves
You shouldn't do this. Take a look at "Stopping" in the Human Interface Guidelines as you could possibly fail for submitting an App that does this, or at the very least provide for a strange user experience.
The link also shows the correct way to handle this, as in the iTunes Music Store app.
Your App will be rejected if you terminate when you cannot reach the Internet.
Sorry.
-t

Resources