iPad - Dismiss keyboard for modal view controller in UIModalPresentationFormSheet mode - ipad

In my iPad app I want to present some view controllers in UIModalPresentationFormSheet modal mode without keyboard.
I use it to display help as an example.
At the moment I use the code found on the one of stackoverflow answers to dismiss it:
// trick to dismiss keyboard in iPad:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
// iPad specific behaviour:
#try
{
Class UIKeyboardImpl = NSClassFromString(#"UIKeyboardImpl");
id activeInstance = [UIKeyboardImpl performSelector:#selector(activeInstance)];
[activeInstance performSelector:#selector(dismissKeyboard)];
}
#catch (NSException *exception)
{
//NSLog(#"%#", exception);
}
}
But I am afraid Apple can reject it in during approval process as it uses private API
I can see Apple developers achieved that in the GarageBand help screens so it must be the 'proper' way to do this.
Would appreciate help as our client do not want to change design concept because of such a slight limitation.
UPDATE:
Just today I was rejected from AppStore:
We found that your app uses one or
more non-public APIs, which is not in
compliance with the App Store Review
Guidelines. The use of non-public APIs
is not permissible because it can lead
to a poor user experience should these
APIs change.
We found the following non-public APIs
in your app:
activeInstance dismissKeyboard
So please do NOT follow this advice:
How to HIDE the iPad keyboard from a MODAL view controller?

As I said in a comment in the mentioned question: you can construct the selector dynamically with NSSelectorFromString(). This will be accepted for the AppStore, your bug will be fixed and your code will not crash.

Related

AdMob, Google Mobile Ad, switching from iAd, bannerView

iOS 9.3, Xcode 7.3, ARC enabled.
I am migrating away from iAd, and I have some general questions regarding best design patterns and how to properly use the Google Mobile Ads framework for banner style ads.
How do you control presentation on ad load and load failure?
My typical approach is to start with the banner view hidden, detect when the ad is loaded, then either animate the banner view in from the top or bottom, or fade in from a stand-in image.
I noticed that GADBannerView class, does not have some of the more convenient properties of an iAd banner, such as isLoaded.
a) Right now I take advantage of the two methods - (void)adViewDidReceiveAd:(GADBannerView *)bannerView and - (void)adView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(GADRequestError *)error, set an instance variable bool for the view controller when either method gets a message, then use that variable for any additional UI changes else where. Is this a good design practice?
b) "deleted", animation works.
c) When the ad fails to load, what happens to the banner view? I notice that its alpha property is still 1.0 and that it is not hidden. In a production environment when an AdMob ad fails to load, is the banner clear? Or does it have a generic stand-in image? In other words, am I going to have to slide in an image to balance the view without the banner view there?
I've read from the basic AdMob tutorial that it doesn't really matter where the banner is, it can be in multiple view controllers, the framework will manage how these multiple banners will be filled. Could someone confirm this behavior? Say, I have two view controllers and I have two different banner views, I don't have to manage the ads? All I have to do is provide the banner view real estate?
Generally speaking, if I used to have iAd for ads and also in-app. purchases through iTunes, then what is the modern day trend? Am I supposed to have ads through AdMob and keep in-app. purchases as they are through Apple? Is that what people are doing now?
Thanks in advance for your answers. I know this maybe too general, but I really want some sort of a fundamental understanding where to head, before I submit anything to Apple.
--
Here is the code for animation I am using:
- (void)adViewDidReceiveAd:(GADBannerView *)bannerView
{
bannerDidLoad = true;
[UIView animateWithDuration:1.0 animations:^{
bannerView.alpha = 1.0;
bannerView.frame = CGRectMake(bannerView.frame.origin.x, bannerView.frame.size.height, bannerView.frame.size.width, bannerView.frame.size.height);
} completion:^(BOOL finished) {
nil;
}];
}
You should really narrow your question down. It's kind of vague. Anyways, yes GADBannerView's will be clear if they fail to receive an ad. Using the delegate methods to know what state the GADBannerView is in is the standard. Animating the alpha property should not be an issue. Not really sure what that last question is asking. You can use any ad network you'd like. If you're using in app purchases already just continue using them and remove the GADBannerView instead of the ADBannerView.

Can I redirect to launcher screen from iOs App?

I am a newbee in iOS app development, and trying to create a small app using Xcode. One of my views has button to close the app. When a user taps this button, then I have to redirect the user to the "launch screen".
But don't know how. Can anybody guide me?
Thanks
First of all there is no way you can 'close' an app programmatically. The alternative solution is to force crash the app using the exit function.
you can use the code below:
exit(0);
Apple strongly discourages you to programmatically quit an iOS application. The standard way to move back to (redirect to) the Launcher screen (which by the way is Home screen for iOS) is when the user presses the Home button.
Calling exit(0), will not invoke the UIApplicationDelegate methods such as applicationWillTerminate: etc., and thus should not be used in general.
Reference of the Same can be found in Apple's Technical Q&A QA1561

UIActivityViewController: Choosing an activity for which permissions are denied leads to a dead end

I am using a UIActivityViewController to implement image sharing.
UIActivityViewController *shareVC = [[UIActivityViewController alloc] initWithActivityItems:#[image] applicationActivities:nil];
[shareVC setCompletionHandler:^(NSString *activityType, BOOL completed){
NSLog(#"completed image export activity: %# - %d", activityType, completed);
}];
[self presentViewController:shareVC animated:true completion:nil];
In testing, I have noticed that if the user selects, for example, "Assign to Contact", but then denies the permission in the ensuing dialog, then they are taken to a screen that says "This app does not have access to your contacts. You can enable access in Privacy Settings.", from which there is no way to back out. The only way for them then to get back to the actual app is to manually restart it.
I'm fairly happy to leave this behaviour as is for now since I don't anticipate any users will be particularly bothered by it, but I'd like to know if there is a sensible way to work around it, and if it is indeed the expected behaviour.
Hmm, maybe you could check if a segue is called when the new "This app does not have access to your contacts. You can..."-Viewcontroller is shown. Then you could manipulate the destinationViewController property of the segue and add for example a button, with an action enabling the user to go back.
All highly theroretical.
I am working on the iPad platform, and in that context presenting a UIActivityViewController directly is wrong according to the documentation, which states that
When presenting the view controller, you must do so using the appropriate means for the current device. On iPad, you must present the view controller in a popover. On iPhone and iPod touch, you must present it modally.
In most ways, the behaviour of the modally presented view controller on iPad seemed perfectly fine, but this case illustrates why it is not appropriate. I don't know how the equivalent case is handled on iPhone / iPod touch as I haven't really looked at those platforms just yet.
Now that I am presenting it in a UIPopoverController, the view explaining that the app doesn't have access to contacts appears within the popup, and is dismissed as the popup is dismissed. Unfortunately it appears that the completion handler is not called in this case; I'm not sure if that's an iOS bug or if I lack understanding of something. It is a slight problem for me at the moment, so I'll have to work around it.
Unfortunately, it seems relatively unlikely that anyone experiencing a related problem will be helped by my question / answer; maybe I'll try to edit the question.

Playhaven SDK Not Working

I integrated Playhaven Full Screen ad in my App. there are two action performing while full screen ad Load. One is Dismiss the view and Second Go to the App Store. I have to check Which Functions are called when both actions are Performed.
I already Tried below Function
-(void)request:(PHPublisherContentRequest *)request contentDidDismissWithType:(PHPublisherContentDismissType *)type{
NSLog(#"Type %#",type);
}
but it Return me the String PHPublisherContentUnitTriggeredDismiss in both case.
How to add Diffrent action on Both Button Clicked ?
Currently the Playhaven SDK doesn't differentiate between the type of dismissal in triggering the the contentDidDismissWithType delegate. I know that this is something we are looking into adding in the future, however.

ads in universal app + ad persisting even when viewController changes

I'm implementing ads for the first time in an app that will be universal. I've followed a few tutorials and sorta|kinda have it working - using adWhirl, iAd, adMob. The tutorials were a bit simplistic though and I'm wondering if there are any open source universal ad template/library projects out there.
I've seen this and while helpful, the tutorial code is kind of broken/limited.
The specific questions I have (iOS5+ universal app):
In an app with a navController where the UIViewController can segue
multiple times to other controllers and then back again, do I need to
set up the ad stuff in each viewController or is there some way I
can have the ad layer/view persist across multiple VC views?
Ad sizes - In my test app, running on iPad I am getting ads but the
size is for iPhone. In adWhirl it didn't seem possible to specify
universal - only iPhone or Android. I've seen other iPad apps that seem to have a problem presenting ads because of the size - ads
appear in weird places, etc. Is there some universal solution to
the issue of ad sizes in universal apps?
For your first question, I would recommend that you use a singleton approach for your adView. You can find a similar singleton approach for an AdMob adView here. Tweaking that with your AdWhirl view instead shouldn't be bad at all. For each view that is displayed then, you could just do something like:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
shared = [AdWhirlMasterViewController singleton];
[shared resetAdView:self];
}
For your second question, I wonder if you can't just make some minor modifications to your adapter code to get iPad ads to show. So, for example, for AdMob adapter's getAd: method, you'd probably have something that looks like:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
adSize = kGADAdSizeLeaderboard;
} else {
adSize = kGADAdSizeBanner;
}
Then create your GADBannerView doing something similar to:
GADBannerView *view =
[[GADBannerView alloc] initWithAdSize:adSize];

Resources