UIDocumentInteractionController disable open in certain apps - ios

I'm currently using a UIDocumentInteractionController for open in functionality. When it opens it shows a list of all apps on the device that can handle that file type.
Is there a way to disable my app sending a document to specific apps, even if they support that file type? For example - if I have a PDF file open in my app and iBooks is on the iPad, if I tap the iBooks icon in the UIDocumentInteractionController, I don't want it to send it to the app.
Ideally - I see this as building a blacklist (or whitelist). For example, it would be great to do this:
- (void) documentInteractionController: (UIDocumentInteractionController *) controller willBeginSendingToApplication: (NSString *) application {
// if app is blacklisted
if ([application isEqualToString:#"com.schimera.WebDAVNavigator"]) {
[self.interactionController dismissMenuAnimated:YES];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"FAIL" message:#"NO" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return
}
}
With this however, the document is still sent to the application even if it is "black listed".
Is this approach at all possible?
Cheers!

Change the UIDocumentInteractionController's URL to an invalid value if the app is blacklisted. In the method -[UIDocumentInteractionControllerDelegate documentInteractionController: willBeginSendingToApplication:].
-(void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application
{
if([application isEqualToString:#"com.evilcorp.badapp"){
controller.URL = nil;
}
}

To offer open file in a specific app (as white list), just add (using swift 3.0):
docController.uti = #"com.yourapp.package";

Related

Cannot Launch an app from within another (iPhone)

I have followed exactly the same tutorial Launch an app from within another (iPhone) but the code is only executing the else part and showing alert, So I am unable to open the second app. You can see the steps I have followed in the link above.
Let's assume that we have two apps called FirstApp and SecondApp. When we open the FirstApp, we want to be able to open the SecondApp by clicking a button. The solution to do this is:
In SecondApp
Go to the plist file of SecondApp and you need to add a URL Schemes with a string iOSDevTips(of course you can write another string.it's up to you).
2 . In FirstApp
Create a button with the below action:
- (void)buttonPressed:(UIButton *)button
{
NSString *customURL = #"iOSDevTips://";
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:customURL]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:customURL]];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"URL error"
message:[NSString stringWithFormat:#"No custom URL defined for %#", customURL]
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
}
Add the custom Url in info.plist
1st image - In Your App which you are opening
2nd Image - In Your App which from you are opening
For full explanation and code visit my blog here

After turn on my Locatiion Service, i would like to load my view

In my Application when i log in, after that Home screen will load at that time in my ViewDidLoad method of Home screen check that location service is ON or not . If it is not turn on then it will appear Error Screen.
Above functionality work fine but after that user immediately go to the setting of their cell , turn ON location service and again tap on application that is running in background will load Home screen and hide Error Screen.
if([CLLocationManager locationServicesEnabled]==YES)
{
NSLog(#"Location Services Enabled");
if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"App Permission Denied"
message:#"To re-enable, please go to Settings and turn on Location Service for this app."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[LocationGuideview setHidden:NO];
}
}
so please tell me how its possible ?????????
What you can try here is add the above code in the application delegate.m file in the applicationDidEnterForeGround and maintain a flag in the plist or user default which you can access across your project
Your code would be something like this then
- (void)applicationWillEnterForeground:(UIApplication *)application
{
//check for location service
if([CLLocationManager locationServicesEnabled]==YES)
{
NSLog(#"Location Services Enabled");
// store a value in plist or user default for further reading set it to YES or whatever you like
}else{
// Location services are not enabled set NO as flag value
}
}
Then inside your view controller in the view did load or view will appear you can read the stored value and do your stuff.
If you are using user defaults please use the synchronize method.

Can I use Apple Push Notification Service to have my app do something without notifying user in iOS 7

My Algorithm wishes to work this way-
If some desired event occurs at my server then I wish to send a small amount of data to every user my app (foreground or background). But, instead of notifying the user I wish my app to do some computation on data and acknowledge server.
Remember user must not be notified.
You can use the content-available key in the push notification data and application:didReceiveRemoteNotification:fetchCompletionHandler:. It could be considered a bit of a hack for your use case and if you try to use it too much you will get limited by Apples system.
You can do this on iOS 7. See the section "Fetching Small Amounts of Content Regularly" at iOS App Programming Guide.
You can send "empty" push notification (no text, no sound, no icon). This kind of notifications
is allowed and can be used for synchronization with server (to avoid the expensive repetitive polling from the app side).
If your app is not running then such a notification won't show up among springboard notifications.
If it is running then it will receive notification - you just have to make sure you don't show the empty ones (if you are also using notifications with actual contents). Your iOS code would look a bit like:
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
NSString *message = nil;
id alert = [userInfo objectForKey:#"aps"];
if ([alert isKindOfClass:[NSString class]])
{
message = alert;
}
else if ([alert isKindOfClass:[NSDictionary class]])
{
message = [alert objectForKey:#"alert"];
}
if (message)
{
if (![message isEqualToString:#""])
{
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle: #"notification"
message: message
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
else
{
//this was an empty notification - here you can enqueue
//your server-synchronization routine - asynchronously if possible
}
}
If you don't intend to use any "real" notifications you don't even have to bother with decoding the message.
If you use ApnsPHP your message generation code would look like this:
$message = new ApnsPHP_Message($device_apns_token);
$message->setText('');
$message->setSound('');
$message->setExpiry(3600);
$push->add($message);

ios webcal request - completion callback?

NSURL *url = [NSURL URLWithString:#"valid_webcal_url"];
if (![[UIApplication sharedApplication] openURL:url])
{
// failure callback
NSLog(#"%#%#",#"Failed to open url:",[url description]);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:LCHLocalizedString(#"SUBSCRIBE_ERROR", nil) message:nil delegate:self cancelButtonTitle:#"Okay" otherButtonTitles: nil];
[alert show];
}
So I've figured out how to see if there was an error loading the webcal, but how can I know when the webcal was loaded successfully? I display a loader when the "subscribe" button is tapped and just need to know when to turn it off.
As already stated in the comments this will put your app in the background with no guaranteed means to automatic return.
Assuming you actually want to invoke a web page (as opposed to doing a web api call) you should probably create a custom subclass of UIViewController with an embedded UIWebView.
Setting your subclass as a delegate of the UIWebView will allow you to react to failure/success. You can even intercept and stop UIWebView calls with - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
Because this is using openURL to retrieve an item using the webcal protocol, there is no visual separation of app and webcal retrieval.
What I'm having to do is listen for the notification UIApplicationWillResignActiveNotification after calling openURL and when the notification is fired I assume it's the webcal taking over from my openURL call.
This is tricky business and a rudimentary fix but hey, it works! Thanks for all help/suggestions.

What do do with Notifications when UIApplicationStateActive

I have set up an app that is registered for remote notifications.
- (void)application:(UIApplication*)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSString *status = [NSString stringWithFormat:#"Notification Received:\n%#",userInfo.description];
NSLog(#"%#",status);
UIAlertView *alert=[[UIAlertView alloc]
initWithTitle:#"didReceiveRemoteNotification"
message:eventName
delegate:self
cancelButtonTitle:#"Hide"
otherButtonTitles:#"View",
nil];
alert.tag = kAlertTypeNotification;
[alert show];
[self vibrate];
if ( application.applicationState == UIApplicationStateActive ) {
// app was already in the foreground
**DO SOMETHING HERE**
}
else {
// app was just brought from background to foreground
}
}
So, when the app is not active, i get that really nifty banner alert, that looks so nice on the iPhone.
However, when the app is open, the only option I seem to have is to present a UIAlertView. This is intrusive in my opinion. Is there a way I can display the banner while application.applicationState == UIApplicationStateActive? Or, is there an open source library that implements this kind of feature?
Thanks for all your help!
I've asked this question more directly here:
Displaying a stock iOS notification banner when your app is open and in the foreground?
The short answer is that as of iOS 9, you cannot show the stock iOS banner when your app is in the foreground.
You will instead have to rely on a home-built or 3rd-part notification banner.
Please duplicate this radar requesting this feature: rdar://22313177
You can do whatever you want when the app is in the foreground. Who says you have to display a UIAlertView?

Resources