I'm using a test library to see me crash report, and I need to know if the app is running from Xcode, I know that exist the DEGUB parameter, but it does not work because if install app from xcode and open it, DEGUB parameter will be in YES.
Thanks.
Not exactly what you want, but you can check if the cable is plugged in, so if it's just for testing the solution should be enough.
[[UIDevice currentDevice] batteryLevel]
or
[[UIDevice currentDevice] UIDeviceBatteryState]
Related
I need to get the UDID of my iPhone to use in my iOS app.
Some info about my app:
My app is not for the public and will never make it to the store, so I can use any 3rd party libraries. It will only be used by some employees at work.
My device will always be plugged into a Mac, while my app is running.
The way I see it, there are only 2 ways this can be accomplished.
Use a third party library to get the UDID inside of my iOS app.
Since the iPhone will always be plugged into a Mac while my app is running, how about getting the UDID via the Mac and transferring it in some way to my app in the iPhone.
Any ideas would be appreciated. Thanks.
Edit: Question is, do you know any 3rd party libraries or a better way to get my app to automatically get the iPhone's UDID while running?
Edit 2: I know this can be done using only my phone because of this web app: http://get.udid.io/
How does this work?
If you're trying to read the UDID to automate something on the Mac, then you can use something like system_profiler SPUSBDataType to get the UDID, for my phone the entry:
Product ID: 0x12a8
Vendor ID: 0x05ac (Apple Inc.)
Version: 7.01
Serial Number: 7bed*********************************33
Speed: Up to 480 Mb/sec
Manufacturer: Apple Inc.
Location ID: 0x1d110000 / 6
Current Available (mA): 500
Current Required (mA): 500
Extra Operating Current (mA): 1600
The line Serial Number is the UDID (I've starred it out as I'm stupidly paranoid).
Note, that without the UDID you could never have got the app onto the phone in the first place.
You could run a small daemon process on the mac, reading this information and creating a bonjour service that provides the information to requestors - it's a SMOP.
It's very simple. Go to Xcode Window and select Devices or you can find it in Organizer.
http://www.raywenderlich.com/2915/ios-code-signing-under-the-hood/organizerudid
From a quick look online, it looks like you can use a private framework called libMobileGestalt.dylib.
After linking the library and importing the header, you should be able to do something like this (reference):
CFStringRef value = MGCopyAnswer(kMGUniqueDeviceID);
NSLog(#"Value: %#", value);
CFRelease(value);
On my Mac, I can find that particular dylib here:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/libMobileGestalt.dylib
Use this code in ios 9
NSUUID *tempUUID = [[UIDevice currentDevice] identifierForVendor];
NSString *stringForUDID = [tempUUID UUIDString];
NSCharacterSet *notAllowedChars = [[NSCharacterSet characterSetWithCharactersInString:#"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"] invertedSet];
NSString *resultString = [[stringForUDID componentsSeparatedByCharactersInSet:notAllowedChars] componentsJoinedByString:#""];
NSLog(#"Final string %#", resultString);
Here is the github project which seems correct for your requirement
Here is the code that works
#import <Foundation/Foundation.h>
#import <CoreFoundation/CoreFoundation.h>
#import <liblockdown.h>
#include <stdio.h>
...
LockdownConnectionRef connection = lockdown_connect();
CFStringRef udid = (CFStringRef)lockdown_copy_value(connection, NULL, kLockdownUniqueDeviceIDKey);
CFShow(udid);
lockdown_disconnect(connection);
Use this: [[[UIDevice currentDevice] identifierForVendor] UUIDString];
I recently upgraded to Xcode 6 and I'm starting to get strange crashes when loading viewcontrollers in AppDelegate.
I found for example that this line of code:
BOOL isIphone = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone;
...didn't always return YES when I was running the app on simulator for iPhone5! Therefore the app tried to load an iPad nib with a crash as result.
Now I only do my testing on the actual device. But can someone please tell me how xcode/simulator can make such a misstake? And how you can protect yourself from it.
Up to the last beta of Xcode6, I was having very odd issues with the simulator. In my case, anything network related would refuse to work after a while, perhaps after computer has gone to sleep and was subsequently woken up. One thing that worked was to restart the simulator (surprise surprise!). Give it a go.
I've written an app specifically for iOS7, and am now attempting to make it work for iOS6.
I'd really like a setting to enable warnings which highlight lines of code which won't work on iOS6. i.e. any calls to code which ONLY work on iOS7.
That way I can immediately identify any lines of code which I need to attend to before catching them during debugging.
Does this even exist?
There is two option to deal with this.
Use MJGAvailability, a drop in header file and it will make warnings if a selector is "too new".
Buy Delpoymate, it can scan your Xcode project and show you any incompatible calls.
If you use an older Xcode next to the newest, than use this snippet:
if ([self respondsToSelector:#selector(newSelector)]){
#if __IPHONE_7_0
[self newSelector];
#endif
} else {
[self oldSelector];
}
There is no way of getting a warning to appear and even if there was how would the IDE now that you would have done something to handle it like the below
if([myObject respondsToSelect:#selector(myiOS7SelectorOnly)]) {
[myObject myiOS7SelectorOnly];
}
It works the other way if you where developing an app for iOS7 and you used a deprecated method that iOS7 API doesn't use any more it would give you a warning but not the other way you will have to wait for it to turn around and crash and throw an unrecognised selector exception.
At some point I had 2 Xcode installed - Xcode 4 and Xcode 5. Xcode 4 did not have API for ios7 and it was showing all incompatibilities.
But I don't know where can you find XCode4 now and will it still show errors in ios7 code or not?
At least you can try this way.
I can find many examples on how to only compile/run code then iOS version is > something, but how do I do it the other way around? I tried the following by running iOS 5.0 in the simulator:
#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_6_0
// Code for iOS < 6.0 here
#endif
But the code inside the #if - #endif is not run on iOS 5.0 in the simulator. How can I do this?
[EDIT]
Ok so I wasn't sure what I wanted it seems, sorry :) The thing is that I want this code in my UITableViewDelegate to be run only if the device is running iOS < 6.0:
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
}
This is because I want to do some styling if I am running iOS < 6, but on iOS 6 I can do this styling much much easier. But a version check at runtime inside this method is not really what I want because then it is to late.
Thank you
Søren
There's a difference between
a compile-time check if you're compiling against a specific SDK and
checking which OS your code is running on
Checking for the __IPHONE_6_0 macro will just check which target you're compiling for... is that what you want? If so, you could use #ifndef __IPHONE_6_0 to check if you are not compiling for iOS 6.
If you want to know which OS your code is running on, you can check MSK's answer.
Here is a run time not compile time check.
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
use it like
if(SYSTEM_VERSION_LESS_THAN(#"6.0"))
{
}
I have an iPad app that makes use in UIPrintInfo (that is being supported from iOS 4.2 and above).
I want my app to run on previous iOS version such as 3.2.
How can I detect in my code the device's iOS version and make the necessary changes according to the device's version?
Thanks in advance,
Class printInfoClass = NSClassFromString(#"UIPrintInfo");
if (printInfoClass != nil )
{
id printInfo = [printInfoClass printInfo];
// Do something
}
Use
[[UIDevice currentDevice] systemVersion]