ios simulator black screen with status bar - ios

I am new to Objective-C and I'm making my first app, a single-view app. When I run my program ,the fullscreen ad that is supposed to appear (I'm using RevMob) appears. However, when I exit the ad I get a black screen with a blue status bar at the top.
I have tried many things, such as setting my main view controller as initial view controller, restarting my computer, changing/removing debugger, resetting the iOS simulator, etc.
My Xcode version is 4.6 and my OS is mac OSX 10.8.4
I don't want to delete Xcode and I also don't want to remove ads because that is my only source of income.
Here is my code:
Appdelegate.m
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
[RevMobAds startSessionWithAppID:#"myappid"];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
RevMobFullscreen *ad = [[RevMobAds session] fullscreen];
[ad loadWithSuccessHandler:^(RevMobFullscreen *fs) {
[fs showAd];
NSLog(#"Ad loaded");
} andLoadFailHandler:^(RevMobFullscreen *fs, NSError *error) {
NSLog(#"Ad error: %#",error);
} onClickHandler:^{
NSLog(#"Ad clicked");
} onCloseHandler:^{
NSLog(#"Ad closed");
}];
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
- (void)dealloc
{
[_window release];
[super dealloc];
}
#end
Appdelegate.h:
#import <UIKit/UIKit.h>
#import "ViewController.h"
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic)UIWindow *window;
#end

There is nothing wrong with the ad code. What seems to be (not) happening is that your app has no content. I suspect that you haven't set up the rootViewController (initial view controller) for the app correctly.
This is what you need to do:
Get rid of all of the app ad code and just make an app that works. All it has to do is correctly show an initial view controller. You could just make a new project in XCode using the Single View Application template.
Add your app code as per this example. You will invoke the code from your initial view controller via a button.
Once that is working, you can add the code into - (void)applicationDidBecomeActive:(UIApplication *)application as per your question. When you dismiss the advert, you should see your initial view controller.

Related

How to remove application from recent apps in Objective C IOS [duplicate]

This question already has answers here:
Prevent iOS from taking screen capture of app before going into background
(10 answers)
Closed 3 years ago.
I am new to IOS development
I want to remove my application from recent apps which is developed in Objective C.
I tried UIApplicationExitsOnSuspend in
info.plist
, but no luck still application is showing in info.plist.
Can anyone help me on this.
Thanks in Advance !!!
You could use concept of the cover window.
When app will resign active state you show your cover, and system will take snapshot of that cover instead of last visible UIViewController.
When app will become active you hide and deallocate your cover window.
Here is example
#import "AppDelegate.h"
#interface AppDelegate ()
#property (nonatomic) UIWindow *coverWindow;
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
self.coverWindow = UIWindow.new;
self.coverWindow.rootViewController = UIViewController.new;
[self.coverWindow makeKeyAndVisible];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[self.coverWindow removeFromSuperview];
self.coverWindow = nil;
}
#end
UIApplicationExitsOnSuspend is deprecated. You shouldn't use it any more. There has been reports of apple rejecting apps with that key. As per apple:
Deprecated
The system now automatically suspends apps leaving the foreground when
they don’t require background execution. For more information, see
About the Background Execution Sequence.
So for now, you are stuck with letting apple handle the background state of apps. Forcefully trying to exit the app by any manner would lead to a rejection from App Store.
UPDATE
I just noticed your comment saying what you actually want. To prevent the Background Snapshot, you can add a custom view to the window. This is similar to the answer posted by Mark Agranal below, but the thing is you don't need to add a new Window or new ViewController. You can simply add a custom view to the window and remove the view when the app reenters active state. In your AppDelegate:
// The view to use as a mask
#property (nonatomic, weak) UIView* coverView;
// Add the view to window
-(void)applicationWillResignActive:(UIApplication *)application
{
coverView = [[UIView alloc]initWithFrame:[self.window frame]];
[self.window addSubview:coverView];
}
// Remove the view to window
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if(coverView != nil) {
[coverView removeFromSuperview];
coverView = nil;
}
}
Note that you can add any view to the window using the above method. The system will take screenshot of the added view and hence the sensitive user data will be protected.

iPhone Objective-c detect Screen Lock

I'm new to make iPhone App with Objective-c
I want to make the App which sends a notification when iPhone screen is locked(Pressed Lock button)
How can I make this app?
I'm trying to make it using "applicationWillSuspend", but
/*----------------------------------------*/
- (void)applicationWillSuspend
{
NSLog(#"WillSuspend");
}
/*----------------------------------------*/
This code doesn't work
I'm not sure when applicationWillSuspend is called
Please, give me some knowledge
#import "AppDelegate.h"
#import <notify.h>
#interface AppDelegate ()
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// iOS8 Notification permit
if ([UIApplication
instancesRespondToSelector:#selector(registerUserNotificationSettings:)]) {
[[UIApplication sharedApplication]
registerUserNotificationSettings:[UIUserNotificationSettings
settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeSound
categories:nil]];
}
return YES;
int notify_token;
notify_register_dispatch("com.apple.springboard.lockstate",
&notify_token,
dispatch_get_main_queue(),
^(int token)
{
uint64_t state = UINT64_MAX;
notify_get_state(token, &state);
if(state == 0) {
NSLog(#"unlock device");
} else {
NSLog(#"lock device");
}
}
);
}
Import this in app delegate #import <notify.h>
Write this piece of code in didFinishLaunchingWithOptions
int notify_token;
notify_register_dispatch("com.apple.springboard.lockstate",
&notify_token,
dispatch_get_main_queue(),
^(int token)
{
uint64_t state = UINT64_MAX;
notify_get_state(token, &state);
if(state == 0) {
NSLog(#"unlock device");
} else {
NSLog(#"lock device");
}
}
);
So once your iPhone gets locked, you will get "lock device" as log. So you can write your code in that block. This will help you.
You can't do that on the iPhone.
But through, Darwin notifications. You can detect the event when the device is locked by "com.apple.springboard.lockcomplete".
Have a look at these links too hopefully it may help you:
1) Lock Unlock events iphone
2) How can I detect screen lock/unlock events on the iPhone?
applicationWillSuspend method doesn't exist natively, but in the AppDelegate.m you can play with applicationWillResignActive and applicationWillResignActive these methods will be called when the user hits the home button and the app will go to the background (here you can keep your connection live, but you should read the apple documentation regarding background tasks because your connection cannot be live forever if the app remains in the background. There are other ways to keep your app up to date like update on push notification etc):
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
and this method will be called when the app will get terminated (closed completely from multitasking).
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
You can handle your connections within these methods.

MobileFirst My migrated iOS project unresponsive if I extend WLAppDelegate, but not if I extend WLCordovaAppDelegate

I've migrated 9 iOS Hybrid apps from MobileFirst 6.3 to MobileFirst 7.1 using MobileFirst Studio. 4 of the apps work fine. But the other 5, the UI is unresponsive to clicks. As part of the automated migration process, the headers of these 5 apps (only) were changed to reference the new WLAppDelegate interface. Strangely I've noticed that if I switch my AppName.h file from extending WLAppDelegate back to extending the original WLCordovaAppDelegate everything works fine. Why? I'd love to move off this deprecated code to your new WLAppDelegate interface.
My header and .m file match the defaults generated by MobileFirst Studio 7.1 when you request a new iOS app so it must be something else.
Here's my non-working .h and .m file
//
// MyAppDelegate.h
//
//
#import <IBMMobileFirstPlatformFoundationHybrid/IBMMobileFirstPlatformFoundationHybrid.h>
#interface MyAppDelegate : WLAppDelegate <WLInitWebFrameworkDelegate> {
}
#end
//
// MyAppDelegate.m
// IssuesReturns
//
//
#import "IssuesReturns.h"
#import <IBMMobileFirstPlatformFoundationHybrid/IBMMobileFirstPlatformFoundationHybrid.h>
#import "CDVMainViewController.h"
#implementation MyAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
BOOL result = [super application:application didFinishLaunchingWithOptions:launchOptions];
// A root view controller must be created in application:didFinishLaunchingWithOptions:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController* rootViewController = [[UIViewController alloc] init];
[self.window setRootViewController:rootViewController];
[self.window makeKeyAndVisible];
[[WL sharedInstance] showSplashScreen];
// By default splash screen will be automatically hidden once Worklight JavaScript framework is complete.
// To override this behaviour set autoHideSplash property in initOptions.js to false and use WL.App.hideSplashScreen() API.
[[WL sharedInstance] initializeWebFrameworkWithDelegate:self];
return result;
}
// This method is called after the WL web framework initialization is complete and web resources are ready to be used.
-(void)wlInitWebFrameworkDidCompleteWithResult:(WLWebFrameworkInitResult *)result
{
if ([result statusCode] == WLWebFrameworkInitResultSuccess) {
[self wlInitDidCompleteSuccessfully];
} else {
[self wlInitDidFailWithResult:result];
}
}
-(void)wlInitDidCompleteSuccessfully
{
UIViewController* rootViewController = self.window.rootViewController;
// Create a Cordova View Controller
CDVMainViewController* cordovaViewController = [[CDVMainViewController alloc] init] ;
cordovaViewController.startPage = [[WL sharedInstance] mainHtmlFilePath];
// Adjust the Cordova view controller view frame to match its parent view bounds
cordovaViewController.view.frame = rootViewController.view.bounds;
// Display the Cordova view
[rootViewController addChildViewController:cordovaViewController];
[rootViewController.view addSubview:cordovaViewController.view];
[cordovaViewController didMoveToParentViewController:rootViewController];
}
-(void)wlInitDidFailWithResult:(WLWebFrameworkInitResult *)result
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"ERROR"
message:[result message]
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
#end
WLCordovaAppDelegate is a deprecated compatibility API to allow easier migration of pre v6.2 apps to 6.2+ apps. It can be used but the recommendation is to use WLAppDelegate.

State Preservation and restoration issue

In my application, I need to make a call, So obviously my app go to background while making a call using native call feature.if the call goes long my app is getting killed by IOS itself. Now i need to restore the last view at the time of making a call. I have used Native restoration. What i did is
1. Set the restoration ID for all the views and view controllers.
2. Override the app delegate restoration methods.
My Issue is,
If my app go to background and come back to foreground, Last view is displayed using preservation and suddenly moved to main view(Default launch view). just like last view blinking while coming to fore ground.
Here is my setting:
app Delegate code :
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
-(BOOL)application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder
{
return YES;
}
-(BOOL)application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder
{
return YES;
}
-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
Main view settings :
Main storyboard contains the login view as a root. Please guide me to fix the restoration issue.
I managed to get rid of the blinking by making the window key and visible in application:willFinishLaunchingWithOptions:.
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window makeKeyAndVisible];
return YES;
}

where do i put the [Scringo initWithAppId:#"" completion:nil];

#import "AppDelegate.h"
#import "Scringo/scringo.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
[Scringo initWithAppId:#"" completion:nil];
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
--
Is this the correct spot? the sidebar doesn't slide out in the emulator and I'm not getting any errors?… help
Use before return statement,
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Scringo initWithAppId:#"YOUR_SCRINGO_APP_ID" completion:nil];
// Override point for customization after application launch.
return YES;
}

Resources