I want to get device model (Settings->General->About->Model) through code. I used:
NSString* model=[[UIDevice currentDevice] model];
Above code returns "iPhone". But I need to get device model value that is shown in (Settings->General->About->Model). For example in my iPhone it is "MD128HN/A. Please see the attached snapshot.
NSString *platform = [UIDevice currentDevice].model;
NSLog(#"[UIDevice currentDevice].model: %#",platform);
NSLog(#"[UIDevice currentDevice].description: %#",[UIDevice currentDevice].description);
NSLog(#"[UIDevice currentDevice].localizedModel: %#",[UIDevice currentDevice].localizedModel);
NSLog(#"[UIDevice currentDevice].name: %#",[UIDevice currentDevice].name);
NSLog(#"[UIDevice currentDevice].systemVersion: %#",[UIDevice currentDevice].systemVersion);
NSLog(#"[UIDevice currentDevice].systemName: %#",[UIDevice currentDevice].systemName);
Related
I am tasked to migrate an IOS game made with Cocos2d-x into Unity. One of the issues I have is that I don't know where Cocos2d-x writes the user's saved data. The Unity version of the app needs to access that data so that the user doesn't lose their progress.
The Cocos2d-x application saves it's data using something like this: userDefault->setIntegerForKey("coins", 35);
Would anybody know what path/location that user's saved data is stored? Are there ways I can find that out? I've already tried to view it on xcode via Window > Devices and Simulators > Installed Apps but the app isn't listed.
Any help would be appreciated. Thanks.
In cocos2d-x v4:
// write string
[[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithUTF8String:value.c_str()] forKey:[NSString stringWithUTF8String:pKey]];
// read string
NSString *str = [[NSUserDefaults standardUserDefaults] stringForKey:[NSString stringWithUTF8String:pKey]];
// read integer
NSNumber *value = [[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithUTF8String:pKey]];
Before V 2.1.2 the info was stored in UserDefault.xml
#define XML_FILE_NAME "UserDefault.xml"
#ifdef KEEP_COMPATABILITY
if (! _isFilePathInitialized)
{
// xml file is stored in cache directory before 2.1.2
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
_filePath = [documentsDirectory UTF8String];
_filePath.append("/");
_filePath += XML_FILE_NAME;
_isFilePathInitialized = true;
}
#endif
I know [[UIDevice currentDevice] uniqueIdentifier] is being rejected, I used :
- (NSString *) uniqueDeviceIdentifier{
NSString *macaddress = [[UIDevice currentDevice] macaddress];
NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
NSString *stringToHash = [NSString stringWithFormat:#"%#%#",macaddress,bundleIdentifier];
NSString *uniqueIdentifier = [stringToHash stringFromMD5];
return uniqueIdentifier;
}
If my method is not approved by Apple, what method can I get a unique identifier?
This project does something similar to what you're doing: https://github.com/gekitz/UIDevice-with-UniqueIdentifier-for-iOS-5. I believe it is being accepted by Apple for now. To actually answer your question, there is no other (public) way of getting a id that is not only unique but the same for every app. #Vishal's method of using:
+ (NSString *)GetUUID {
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
return [(NSString *)string autorelease];
}
and #JeffWolski's method of using:
[[NSUUID UUID] UUIDString];
work if you don't need the device id to be consistant between apps and just need a way to identify that specific device within your own. If you need a device ID that works between apps, you will need to use the devices MAC address either using your code or a open source project.
UPDATE
I just found another solution. You can use [[UIDevice currentDevice] identifierForVendor]. Again, this device id will be unique to your app. http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/occ/instp/UIDevice/identifierForVendor
This is new in iOS 6. It gives you a UUID that conforms to RFC 4122.
[[NSUUID UUID] UUIDString];
Use this CFUUIDCreate() to create a UUID:
+ (NSString *)GetUUID {
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
return [(NSString *)string autorelease];
}
And the UDID is only deprecated in iOS 5.
One thing you could do it use openUDID to replace it.
I am showing apple maps with directions from start and end destination.I want it to open and start siri when user opens the map with the route.For some reason its opening the url successfully but not opening the siri to guide the user.
Code used for it is as shown below:
NSString* versionNum = [[UIDevice currentDevice] systemVersion];
NSString *nativeMapScheme = #"maps.apple.com";
if ([versionNum compare:#"6.0" options:NSNumericSearch] == NSOrderedAscending)
nativeMapScheme = #"maps.google.com";
NSString* url = [NSString stringWithFormat: #"http://%#/maps?daddr=%#&saddr=%f,%f",nativeMapScheme,[description stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],mylat, mylon];
NSLog(#"Location - %#",url);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
I want to develop an iOS application where i want to get any PDF/Doc/XLS file present in my Mail/Safari by using UIDocumentInteractionController and finally upload them to my local server.
I can able to upload image file present in my iPhone to my local server.
But my question is, can i able to fetch PDF/Doc/XLS file(present in safari/ Mail application) to my application by using UIDocumentInteractionController & upload them to my local server?
It is indeed possible to Import a file from another application using UIDocumentInteractionController in case of an iPad app. All you need to do is in info.plist of you application you need to add supported document formats. Add applicationDidFinshWithLaunchingOptions delegate method to your app in application delegate class in the following manner.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self applicationDidFinishLaunching:application];
if (launchOptions && [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey])
{
NSString* path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSURL *url=[launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
NSString *sourceFilePath=[url path];
NSFileManager *fileManager=[NSFileManager defaultManager];
NSData *fileData=[fileManager contentsAtPath:sourceFilePath];
NSString *fileName = [NSString stringWithFormat:#"test.pdf"];
NSString *updatedFilePath = [path stringByAppendingPathComponent:fileName];
BOOL hasWrittenSuccessfully = [fileData writeToFile:updatedFilePath atomically:TRUE];
}
return YES;
}
You can't fetch documents, you can tell iOS that your app can open PDF/Doc/XLS.
Do this by adding supported filetype to you info.plist:
http://developer.apple.com/library/ios/#documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/RegisteringtheFileTypesYourAppSupports.html#//apple_ref/doc/uid/TP40010411-SW1
I want to make an app in iphone such that it displays the history of safari browser in iphone. Means I want to access safari cookies through other app. This is the first time m placing a query on overflow...... can anybody please let me know about this... please do reply
i don't know whether it will work or not but you can try this using NSHTTPCookie and NSHTTPCookieStorage classes...
code would be similar this
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSURL *URL;
NSArray *cookies;
NSString *cookieString = #"";
cookies = [cookieStorage cookies];
if([cookies count] > 0) {
NSHTTPCookie *cookie =[cookies objectAtIndex:0];
cookieString = [NSString stringWithFormat: #"%#=%#", [cookie name], [cookie value]];
NSLog(cookieString);
}