Change iOS Simulator Device Name - objective-c

I'm working on a big project with many view controllers. Progression through these views depends on data being filled in on lengthy forms.
In my not-so-clever way i'm autofilling data so that i can speed through to the current feature I'm working on. I was using a conditional like this...
if(
[[[UIDevice currentDevice] name] hasPrefix:#"Rob"] ||
[[[UIDevice currentDevice] name] hasPrefix:#"iPad Simulator"]
)
{
self.label.text = #"xxx";
...
}
...this worked great because I could test both on my iPad and in the simulator. Now the client wants to also be able to test on their simulator, so I can't leave my autofill in. I'm thinking the simplest solution would be to just change the name of the simulator.
In Settings.app on the simulator, it's not editable. I also haven't seen then text "iPad Simulator" or "Simulator" show up in any files in ~/Library/Application Support/iPhone Simulator/5.1. I've done searches on setting plist properties, but no luck.
Does anyone know how to accomplish this?

You'll be able to check if it's running the iPhone Simulator by checking the model rather than the name of the current device. Something like the following should do:
if ([[[UIDevice currentDevice] model] isEqualToString:#"iPhone Simulator"]) {
// Run for iPhone simulator
}
Note: You'll need to use "iPad Simulator" for when you use the iPad Simulator
Also, your current code with hasPrefix is not secure at all. Rob is a common name so if someone else has a device with the name of their device beginning with Rob then it'll expose your test information. I highly suggest you just target this autocomplete for the simulator only

Just create a new class and put your loading logic there.
After that, call this class from your delegate didFinishLaunchingWithOptions method.
With this, you can comment the above call whenever you want or better, check if the data is already loaded and ignore it.

Related

UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes: and viewWillAppear: order

a quick question for any of you who might have an idea:
I recently encounter a bug in on of my app, and that have raised a little question.
The bug was caused by a piece of code trying to access to an array not yet set.
The funny buisness here was that the same code worked absolutely fine on an iPad Air, and crashed on an iPad Pro.
Indeed, i was trying to access the array in the collectionView:cellForItemAtIndexPath: method of my controller, and the array was initialized in the viewWillAppear: method of the same controller.
In any device that i have tried, exepted on the iPad Pro, the collectionView:cellForItemAtIndexPath: method was always called after the viewWillAppear:, but on the iPad Pro, it is the other way.
I easily fixed the issue, but i'm still wondering why the iPad Pro have a different cycle than the other. Anyone have a clue about that?
(I'm on Objective-C, iOS 11.0)
Change the collectionView:cellForItemAtIndexPath method for conditions like following
if (array has data || data is downloading) {
show activity indicator
} else {
show data
}
Reload collection view when data loads

KIF (Keep It Functional) distinguish between iPhone and iPad

I am using KIF for testing the functionality of an app. However, this app has two versions, one is for iPad, and the other one is for iPhone. Is there a global variable or something that indicates if I am running my test in iPad or iPhone? I'd like to use it (e.g. in a conditional) to take advantage and just make a few modifications in the iPhone tests that I have already finished.
You can define macro
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone)
That's how we used it.

Xcode iOS: Calling a number from the app

I across the following code:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel://8005551212"]];
on : Making phone calls on iPhone
But, it does not work for me in the simulator.
I have connected the IBAction(callphone) to the ViewController(TouchUpInside). I am now not sure, is it because I am checking my code in simulator? I do not get a dialog box. Please advice.
I tried putting log statements and the action does get called since the log stamtments that I wrote to test is being printed
Can you make a phone call from your Mac? No. That's why the simulator doesn't work when you try to open a tel:// URL. You must do this from a device that can make a call: an iPhone, but not an iPad or iPod touch.

Upgrading app from IOS4 to IOS5

I have an IOS5 app which uses following function
[self.presentingViewController dismissModalViewControllerAnimated:YES];
and who works perfectly on IOS4 but suddenly I discovered that this function doesn't exists on IOS5 so I had to use this other equivalent one
[self.parentViewController dismissModalViewControllerAnimated:YES]
Now I've got the following issue: IOS4 users are not able to install my app due to this non existing function in IOS4 and what is even worse, the app is available on Apple's App Store but is only functional of IOS5 users. Another related issue us that the app suddenly stopped working on iPads equipped with Wifi, those connected to 3G networks operate normal.
Is there anything I missed trying to compile this new app version?
Thanks in advance!
You can check for existence of the property like this:
if([self respondsToSelector:#selector(presentingViewController)])
[self.presentingViewController dismissModalViewControllerAnimated:YES];
else
[self.parentViewController dismissModalViewControllerAnimated:YES];
Code it this way:
if ([self respondsToSelector:#selector(parentViewController)])
[self.parentViewController ...];
else
[self.presentingViewController ...];
(This is uncompiled, untested, etc.)
The point is that you can (and should) test for capabilities, and then act accordingly. In this case, if the iOS5 method is available, use that one. If not, use the old one, which also means its a pre-iOS5 device.
The way to go is twofold:
compiling your app against the latest SDK version, but also set the deployment target to the oldest version that you want to support; this will ensure that the app is listed properly in the App Store;
checking before using any method/feature that is only available on a later version; this will ensure that you app will not crash and can be done by means of conditional compilation, e.g.:
k
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
if ([[UIApplication sharedApplication] respondsToSelector:#selector(beginBackgroundTaskWithExpirationHandler:)])
{
UIBackgroundTaskIdentifier bgTask = [[UIApplication sharedApplication] eginBackgroundTaskWithExpirationHandler:^{}];
// Perform work that should be allowed to continue in background
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
}
#endif
this is quite convoluted if you have to do it in many places. You may have a look at this very good post to learn how to improve upon that example.
I have built a category that add presentingViewController on iOS 4.
(It disables itself on iOS 5.)
It works seamlessly; Just include 2 files.
Please see backward-modal.
I hope this benefits you as much as it does to me; It makes your code more clean!

Better way to detect if isIpad?

I have an universal app that changes the screen layout based on what device the user has.
It seems to work pretty good, but I've had one user call in (and send me screen shots) of his iPhone 4 showing him the iPad view instead of the iPhone view. I haven't been able to duplicate it on any of the phones we have around here, but I'm wondering if there there is a better way to do this since iOS 4.3 has come out.
+(BOOL)isIpad{
return ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad);
}
Alternately, is there just a way to detect screen size? I mostly use this to determine how wide elements in a table should be, but if Apple comes out with iPad 3 with retina display, it would be nice to have the app just adjust everything accordingly.
Also useful if the app is in portrait or landscape. Make it so that it just anchors to the edges like elements in WPF.
When loading XIBs for a universal app this, or what you're already doing, seems to be the only way:
NSString *xibName = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)?#"SomeView~iPad":#"SomeView";
As for screen size this should work:
CGRect screenSize = [[UIScreen mainScreen] bounds];
This is like a bazillion years old, but came across it in google so I figured I'd post a poorly documented but very useful feature. If you add ~ipad to the end of the filename for your iPad specific nib it will automatically load that one instead. Same logic as #2x for loading images. So your iPhone nib would be named myview.xib and your ipad myview~ipad.xib and iOS will correctly load the ipad version wherever needed. Fancy!
UIUserInterfaceIdiomPad is now deprecated. The new way to do it would be using TraitCollections. It can only be called on Views.
-(BOOL) isiPad{
return self.view.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassRegular && self.view.traitCollection.verticalSizeClass == UIUserInterfaceSizeClassRegular;
}
Refer Apple Documentation here
Probably it has a previous version of the app and conflict with the new!
Try to remove old one and reinstall new! It works! I already encountered this issue.