Xcode 6.1 : Snapshotting a view that has not been rendered - objective-c

I'm using storyboard for my sample project. The architecture is Login View Controller and Home PageView controller. User clicks on button in Home PageView controller to start local notification.
-(IBAction)startLocalNotification { // Bind this method to UIButton action
NSLog(#"startLocalNotification");
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:7];
notification.alertBody = #"This is local notification!";
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.soundName = UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber = 10;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
This code goes in AppDelegate file :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
if ([UIApplication instancesRespondToSelector:#selector(registerUserNotificationSettings:)]){
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}
[launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
// Override point for customization after application launch.
return YES;
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
NSLog(#"didReceiveLocalNotification");
}
Now after pushing app to background state I'm getting below message in console but local notification is working fine as expected.
Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
What this message is related to?

I have what I believe could just about stand up as an 'answer'... And that is that there's almost certainly nothing wrong, but maybe a problem with iOS (8.1.3/8.2). As far as I can tell, it's innocuous.
I played around with this and found that it was related to UITextField/Keyboard.
So a single view app with just a text field, follow the steps below (only tried on iPad):
Build and run
Put focus in text field
Close keyboard (it should have opened)
Click home button (app enters background)
Return to app
Click home button (app enters background)
Observe log output.
Here's a sample project: https://github.com/duttski/TestForStrangeSnapshotMessage .
Filed as a bug and trying to get some information through the dev forums too.
UPDATE: I think this may be fixed in later versions. But I haven't tested it. After speaking on the dev forums I was told that this isn't something to worry about.

Related

How to get iBeacon Notification when the app is in Background mode in ios 10 and above?

I have implemented iBeacon Notification in iOS 10 using objective-c. Can some one help me solve this problem to get the iBeacon in background mode in ios 10?
Even if the app is not running, location events (related to the beacons in this case) are handled the same way as any other app launching events. Every time a phone enters or exits a region while the app is terminated, it will be automatically launched.
application:didFinishLaunchingWithOptions: method (of AppDelegate class) is called with UIApplicationLaunchOptionsLocationKey key existing in launchOptions parameter.
When you verify this key exists (so location was the reason that your app was launched) you should create new instance of ESTBeaconManager class, set delegate to AppDelegate object (or any other object that is working as ESTBeaconManagerDelegate and was created before this event occurred) and start monitoring.
Region you are passing to the startMonitoringForRegion: method is not important, as ESTBeaconManager delegate will receive the most recent region information. You can just pick any of the ones your app registered in iOS. After Monitoring is revoked, app will automatically receive most recent entered/exited region event in beaconManager:didEnterRegion: or beaconManager:didExitRegion: method.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if([launchOptions objectForKey:#"UIApplicationLaunchOptionsLocationKey"])
{
self.beaconManager = [ESTBeaconManager new];
self.beaconManager.delegate = self;
// don't forget the NSLocationAlwaysUsageDescription in your Info.plist
[self.beaconManager requestAlwaysAuthorization];
[self.beaconManager startMonitoringForRegion:[[ESTBeaconRegion alloc]
initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID
identifier:#"AppRegion"]];
}
return YES;
}
-(void)beaconManager:(ESTBeaconManager *)manager didEnterRegion:(ESTBeaconRegion *)region
{
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = #"Enter region";
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}
-(void)beaconManager:(ESTBeaconManager *)manager didExitRegion:(ESTBeaconRegion *)region
{
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = #"Exit region";
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}

FBloginview not working in iOS5

I am using fb ios sdk 3.5, and i tried to run sample project named Scrumptious came with the package, it uses FBLoginView for login purpose, but FBLoginView is not working on iOS5.0. When i press the FBLoginVIew, it stays pressed and nothing ops up. While its working fine for iOS6. It opens up safari for login. I have test on simulator only as i dont have device. Is it that FBloginView is just for iOS6 devices?
- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView {
// Upon login, transition to the main UI by pushing it onto the navigation stack.
SCAppDelegate *appDelegate = (SCAppDelegate *)[UIApplication sharedApplication].delegate;
[self.navigationController pushViewController:((UIViewController *)appDelegate.mainViewController) animated:NO];
}
- (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView {
// Facebook SDK * login flow *
// It is important to always handle session closure because it can happen
// externally; for example, if the current session's access token becomes
// invalid. For this sample, we simply pop back to the landing page.
SCAppDelegate *appDelegate = (SCAppDelegate *)[UIApplication sharedApplication].delegate;
if (appDelegate.isNavigating) {
// The delay is for the edge case where a session is immediately closed after
// logging in and our navigation controller is still animating a push.
[self performSelector:#selector(logOut) withObject:nil afterDelay:.5];
} else {
[self logOut];
}
}

Unable to detect iPhone Retina 4-inch screen size in simulator

I want to make my iOS application support iPhone 5. So I created a separate xib set for iPhone 5 size. Then I load each xib by checking the screen height.
This is the splash screen loading code inside the AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *viewController1;
if ([UIScreen mainScreen].bounds.size.height==480) {
viewController1 = [[SplashScreen alloc] initWithNibName:#"SplashScreen" bundle:nil];
}
if ([UIScreen mainScreen].bounds.size.height==568) {
viewController1 = [[SplashScreen alloc] initWithNibName:#"SplashScreen5" bundle:nil];
}
self.window.rootViewController = viewController1;
[self.window makeKeyAndVisible];
return YES;
}
But when I change the simulator into Retina 4-inch, my code doesn't get the emulator size. It always executes the 480 if condition.
But other apps I created like this are working properly.
What is the reason for this?
I'm having the exact same problem right now (at the worst moment, of course....).
It did work properly for several weeks, and for a unknown reason, the simulator suddenly considers the 4in simulated device as a 3.5in screen.
cleaning, reset, reboot : same situation...
EDIT : ok, problem solved. T'was because of a missing Default image in the -568#2x format. I knew that was a condition to make the system work, but xcode had apparently decided to get rid off the one I chose. oh well...

Set a new window.rootViewController before the view gets loaded

So I am trying to install this Navigation Framework in my app:
https://github.com/weissi/FRLayeredNavigationController
http://www.youtube.com/watch?v=k9bFAYtoenw&feature=plcp
Now, if you look at the attached image, I have my login screen. Once the login is done, I do a Segue Modal push into my "home" page and in there, I want to start having the FRLayeredNavigationController once I reach my homepage. Is that possible while using the storyboard? According to the Youtube Video, one would usually use the FRLayeredNavigationController by doing:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
HomeViewController* homeController = [[HomeViewController alloc] init];
FRLayeredNavigationController* lnc = [[FRLayeredNavigationController alloc] initWithRootViewController:homeController];
self.window.rootViewController = lnc;
}
[self.layeredNavigationController pushViewController:vc inFrontof:self maximumWidth:NO animated:YES];
I have not fount a way to do this using Segue's... But the way I have accomplish this is as follows:
Providing the login was successful and you are wanting to move onto the next part of you app, then the following is how you would transition:
- (void)loginSucceeded
{
UIViewController * vc = (UIViewController*)[self.storyboard instantiateViewControllerWithIdentifier:#"someIdentifier"];
FRLayeredNavigationController * nav = [[FRLayeredNavigationController alloc] initWithRootViewController:vc configuration:^(FRLayeredNavigationItem *item) {
item.width = 300;
item.nextItemDistance = 90;
}];
[self presentViewController:nav animated:YES completion:nil];
}
You will need to set the Storyboard ID to that specified in the above methos. This can be found in the 'Identity Inspector' tab when viewing the storyboard and selecting the ViewController you have designed.
Also you will no longer need to perform the segue you had previously created, so delete that.
Any future view controllers you want to 'push' onto the screen, you simply need to call the following:
UIViewController * vc = (UIViewController*)[self.storyboard instantiateViewControllerWithIdentifier:#"SomeStoryboardIDHere"];
[self.layeredNavigationController pushViewController:vc inFrontOf:self maximumWidth:YES animated:NO];

Prompt login alert with Twitter framework in iOS5?

As you all may know, since iOS5 there is a native Twitter framework which make it easy to post tweets from your app.
Is there a way to prompt an alert that forwards the user to the settings app and ask for username and password?
I know that i could solve the problem with the following code:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=TWITTER"]];
But thats undocumented code..
Thanks in advance
Regards Billy
(My first post on SO)
In iOS5.1, we should use TWTweetComposeViewController to show the dialog since apple rejects apps using prefs:root=TWITTER.
But, I didn't like showing the tweet screen and keyboard
so I figured out the way to hide them, but show the pop up screen.
UPDATE:
Apple approved my app using this trick.
TWTweetComposeViewController *viewController = [[TWTweetComposeViewController alloc] init];
//hide the tweet screen
viewController.view.hidden = YES;
//fire tweetComposeView to show "No Twitter Accounts" alert view on iOS5.1
viewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
if (result == TWTweetComposeViewControllerResultCancelled) {
[self dismissModalViewControllerAnimated:NO];
}
};
[self presentModalViewController:viewController animated:NO];
//hide the keyboard
[viewController.view endEditing:YES];
//this approach doesn't work since you can't jump to settings
// [self dismissModalViewControllerAnimated:NO];
You don't need to implement this, if you set up your Twitter integration to make a post on Twitter and iOS detects that there is no Twitter account set up it will do this automatically for you!
This is a screenshot of one of my apps running on my iPhone 4S on iOS 5.1
The removal of Preferences links is in reference to custom actions by the developer, as in linking to your own preferences menu. This does not apply because not only is Twitter a built in function of iOS 5 but the UIAlertView that pops up to notify you isn't handled by the developer, it is an automatic function of iOS.
Here i found the way :
Display custom alert if no twitter account has been setup on your device settings:
if (![TWTweetComposeViewController canSendTweet]) {
UIAlertView *alertViewTwitter = [[[UIAlertView alloc]
initWithTitle:#"No Twitter Accounts"
message:#"There are no Twitter accounts configured. You can add or create a Twitter account in Settings."
delegate:self
cancelButtonTitle:#"Settings"
otherButtonTitles:#"Cancel",nil] autorelease];
[alertViewTwitter show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex==0) {
TWTweetComposeViewController *ctrl = [[TWTweetComposeViewController alloc] init];
if ([ctrl respondsToSelector:#selector(alertView:clickedButtonAtIndex:)]) {
[(id <UIAlertViewDelegate>)ctrl alertView:alertView
clickedButtonAtIndex:0];
}
[ctrl release];
}
}
Hope this will make sense :)
It's not possible, although it should automatically ask the user to login, if the user isn't logged in already.
As of iOS 5.1 that feature has been removed, as seen here