I use this code to initialize iCloud access (I've got it from an Apple tutorial)
- (void)initializeiCloudAccess {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSURL *ubiq = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
if (ubiq)
NSLog(#"iCloud is available.\n");
else
NSLog(#"iCloud is not available.\n");
});
}
But I receive NSInvalidArgumentException with reason unrecognized selector sent to instance ... when I try to get ubiq;
Can anyone explain to me what's the problem with this code?
Check that your project is configured to use the latest iOS SDK (at least 5.0 to use iCloud) and that your device or simulator has iOS 5 or greater. If you need to target previous versions of iOS as well, you need a condition before sending the message:
if (NSClassFromString(#"NSUbiquitousKeyValueStore")) {
// iCloud API available, safe to send URLForUbiquityContainerIdentifier message
...
}
Related
I want to send commands from mobile device with the mobile-SDK to the onboard computer (Raspberry Pi 3) on the drone (Matrice 600) running the onboard-SDK. Therefore I am trying to make the sample from DJI work. I followed the guide (https://developer.dji.com/onboard-sdk/documentation/guides/component-guide-mobile-communication.html) and the link (https://developer.dji.com/onboard-sdk/documentation/sample-doc/msdk-comm.html). I used the code from https://github.com/dji-sdk/Onboard-SDK/tree/3.8/sample/linux/mobile for onboard-SDK and the iOS sample https://github.com/dji-sdk/Mobile-OSDK-iOS-App.
The Mobile App is saying it is sending commands but the onboard program does not recognize any and the log is not displaying any errors.
I did not change anything on the code besides my API Key I put in the variable. It says the product has been registered right. Also, the UART connection between the drone and the raspberry seems fine since every other example I tried is working. Also, the connection between the mobile device and the drone is working since other Apps like DJI-Go are able to send commands to the drone, which are then executed.
I am using the simulator on the DJI-Assistant Windows Program.
I feel like the problem is already in the App because I tried to log at different sections of the code and it seems like code that should be executed is not executed. I did not develop iOS apps so I do not really know what is going on exactly but maybe you can help me out.
For example code inside here is not executed. Does that mean he did not manage to finish "Sending"?
From "Mobile-OSDK-iOS-App/MOS/Network/MOSProductCommunicationManager.m"
[fc sendDataToOnboardSDKDevice:data withCompletion:^(NSError * _Nullable error) {
if (error) {
// Handle error locally
} else {
NSString *key = [self commandIDStringKeyFromData:data];
[self.sentCmds setObject:ackBlock forKey:key];
}
completion(error);
}];
Also in the log there are no other logs like these following up:
From "Mobile-OSDK-iOS-App/MOS/ViewController/MOSJSONDynamicController.m"
[self.appDelegate.model addLog:[NSString stringWithFormat:#"Sending CmdID %# with %ld Arguments", cmdId, (unsigned long)arguments.count]];
weakCell.commandResultLabel.text = #"Sending...";
[self.appDelegate.productCommunicationManager sendData:data
withCompletion:^(NSError * _Nullable error) {
[self.appDelegate.model addLog:[NSString stringWithFormat:#"Sent CmdID %#", cmdId]];
weakCell.commandResultLabel.text = #"Command Sent!";
}
andAckBlock:^(NSData * _Nonnull data, NSError * _Nullable error) {
NSData *ackData = [data subdataWithRange:NSMakeRange(2, [data length] - 2)];
uint16_t ackValue;
[ackData getBytes:&ackValue length:sizeof(uint16_t)];
NSString *responseMessage = [NSString stringWithFormat:#"Ack: %u", ackValue];
[self.appDelegate.model addLog:[NSString stringWithFormat:#"Received ACK [%#] for CmdID %#", responseMessage, cmdId]];
weakCell.commandResultLabel.text = responseMessage;
}];
Here are screenshots of the logs:
I found out the standard (master) branch for the iOS-Sample-App repository is the old version 3.1, which did not work. Since there is no documentation on this I used this one because I did not know other versions exist until checking out the different branches.
In the end, version 3.3 worked best for me.
This is the link to the newest branch/version (3.4): https://github.com/dji-sdk/Mobile-OSDK-iOS-App/tree/3.4
I'm trying to write an app to auto answer an iphone when there are incoming calls.
The app can be launched by the user and run in the background.
I'm trying to use the IOS Private APIs to do this, but no success.
This is for testing purpose only and won't be submitted to the app store so using private APIs shouldn't be a problem. The phones aren't jailbroken though.
This is what I have in my AppDelegate.m file (didFinishLaunchingWithOptions):
id callCenterId = [TUCallCenter sharedInstance];
NSLog(#"callCenterId: %#", callCenterId);
TUCallCenter *object = [[TUCallCenter alloc] init];
NSLog(#"object: %#", object);
[object handleCallModelStateChanged: ^{
NSLog(#"this is an incoming call");
}];
When I run the app, I do see some outputs in the debug panel:
2016-02-01 10:32:38.849 AutoAnswer[312:63056] callCenterId: <TUCallCenter: 0x134642b40>
2016-02-01 10:32:38.851 AutoAnswer[312:63056] object: <TUCallCenter: 0x1346496c0>
But nothing is shown when I dial the phone when the app is in the foreground. I can't even get that to work, so forget about making it work in the background.
Any help would be appreciated.
i'm new of using PLCrashReport and i whant to make symbolication client side. I khnow that there is many disadvantages but i want to try it, can you help me please.
I used the last version of CrashReporter and this what i done in the appDelegate class refering to this example http://plcrashreporter.googlecode.com/svn/tags/plcrashreporter-1.1-rc1/Documentation/API/example_usage_iphone.html.
The is a topic that talk about this here
PLCrashReporter - How to symbolicate crash data in-process?
Link to the library:
https://www.plcrashreporter.org/.
(void) applicationDidFinishLaunching: (UIApplication *) application {
PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];
NSError *error;
if ([crashReporter hasPendingCrashReport])
[self handleCrashReport];
if (![crashReporter enableCrashReporterAndReturnError: &error])
NSLog(#"Warning: Could not enable crash reporter: %#", error);
You are linking to an old repository and documentation. The website of PLCrashReporter is https://www.plcrashreporter.org/ and the documentation is https://www.plcrashreporter.org/documentation/api/v1.2/
To enable client side symbolication you need to initialize it with a configuration like this:
PLCrashReporterSignalHandlerType signalHandlerType = PLCrashReporterSignalHandlerTypeBSD;
PLCrashReporterSymbolicationStrategy symbolicationStrategy = PLCrashReporterSymbolicationStrategyNone;
PLCrashReporterConfig *config = [[PLCrashReporterConfig alloc] initWithSignalHandlerType: signalHandlerType
symbolicationStrategy: symbolicationStrategy];
PLCrashReporter *crashReporter = [[PLCrashReporter alloc] initWithConfiguration: config];
This is based on the latest version 1.2 available on the download page: https://www.plcrashreporter.org/download
But you are right, you should not do this:
It is slow, caused the device to lock up when the crash happens for a few seconds
It requires your app to include symbols which increased the app size by 30-50% (on average)
You won't get line number information for your code.
You should instead symbolicate the crash reports using the dSYM, e.g. on your Mac.
the App we are working on was rejected because the Device in the Review Process was detected as jailbroken ^^
To detect a jailbroken Device, several Tests were performed:
NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
// scan for itunes metadata
BOOL isDirectory = NO;
NSString* directoryPath = [bundlePath stringByAppendingPathComponent:#"SC_Info/"];
BOOL directoryIsAvailable = [[NSFileManager defaultManager] fileExistsAtPath:directoryPath isDirectory:&isDirectory];
BOOL contentSeemsValid = ([[[NSFileManager defaultManager] contentsOfDirectoryAtPath:directoryPath error:NULL] count] == 2);
if (directoryIsAvailable && contentSeemsValid) {
return YES;
}
contentSeemsValid = [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:#"%#/iTunesMetadata.plist", bundlePath]];
if (contentSeemsValid) {
return YES;
}
// scan for cydia app
NSURL* testURL = [NSURL URLWithString:#"cydia://"];
if ([[UIApplication sharedApplication] canOpenURL:testURL]) {
return YES;
}
// scan for paths available
NSArray* paths = #[#"/Applications/Cydia.app", #"/Applications/RockApp.app", #"/Applications/Icy.app", #"/usr/sbin/sshd", #"/usr/bin/sshd", #"/private/var/lib/apt", #"/private/var/lib/cydia", #"/private/var/stash", #"/usr/libexec/sftp-server"];
for (NSString* string in paths) {
if ([[NSFileManager defaultManager] fileExistsAtPath:string]) {
return YES;
}
}
// scan for forking
int forkValue = fork();
if (forkValue >= 0) {
return YES;
}
// try to write in private space
NSString* testString = #"test";
NSError* error = nil;
[testString writeToFile:#"/private/test.txt" atomically:YES encoding:NSUTF8StringEncoding error:&error];
if (error == nil) {
return YES;
}
// seems not jailbroken
return NO;
One (or more) of these Tests return YES on the Devices Apple use for Review, but none of our DevDevices. Which one could it be? Does anybody know more Details about the Devices Apple use for the Review? Any Hints or other Guesses? (The Context from the App is HealthCare in Hospitals, so we need to be sure that the Patient Data were save)
Best Regards,
Zeek
From https://www.theiphonewiki.com/wiki/Bypassing_Jailbreak_Detection
While there are countless ways apps can implement checks for jailbroken devices, they typically boil down to the following:
Existence of directories - Check your file system for paths like /Applications/Cydia.app/ and /private/var/stash, amongst a handful of others. Most often, these are checked using the -(BOOL)fileExistsAtPath:(NSString*)path method in NSFileManager, but more sneaky apps like to use lower-level C functions like fopen(), stat(), or access().
Directory permissions - Check the Unix file permissions of specific files and directories using NSFileManager methods as well as C functions like statfs(). Far more directories have write access on a jailbroken device than on one still in jail.
Process forking - sandboxd does not deny App Store applications the ability to use fork(), popen(), or any other C functions to create child processes on non-jailbroken devices. sandboxd explicitly denies process forking on devices in jail. if you check the returned pid on fork(), your app can tell if it has successfully forked or not, at which point it can determine a device's jailbreak status.
SSH loopback connections* - Due to the large portion of jailbroken devices that have OpenSSH installed, some apps will attempt to connect to 127.0.0.1 on port 22. If the connection succeeds, it means OpenSSH is installed and running on the device, therefore it is jailbroken.
system() - Calling the system() function with a NULL argument on a device in jail will return 0; doing the same on a jailbroken device will return 1. This is since the function will check whether /bin/sh exists, and this is only the case on jailbroken devices.[1]
dyld functions - By far the hardest to get around. Calling functions like _dyld_image_count() and _dyld_get_image_name() to see which dylibs are currently loaded. Very difficult to patch, as patches are themselves part of dylibs.
*Only a very small number of applications implement this (as it is not nearly as effective as the others)
These methods seem like they would be less likely to be rejected by apple and are very simple to use.
The above passage has been edited for brevity
I am using a UIManagedDocument in iOS 5.0, running the app on the simulator, using XCode 4.2 under OSX 10.6. The code in question looks as follows:
if (![[NSFileManager defaultManager] fileExistsAtPath:[self.photoDatabase.fileURL path]]) {
// does not exist on disk, so create it
[self.photoDatabase saveToURL:self.photoDatabase.fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
[self setupFetchedResultsController];
[self fetchFlickrDataIntoDocument:self.photoDatabase];
}];
} else if (self.photoDatabase.documentState == UIDocumentStateClosed) {
// exists on disk, but we need to open it
// *** the following line generates the message ***
[self.photoDatabase openWithCompletionHandler:^(BOOL success) {
//[self setupFetchedResultsController];
}];
} else if (self.photoDatabase.documentState == UIDocumentStateNormal) {
// already open and ready to use
[self setupFetchedResultsController];
}
Running the marked line creates the following message on the log:
2012-01-10 22:33:17.109 Photomania[5149:4803] NSFileCoordinator: A surprising server error was signaled. Details: Connection invalid
After the message is sent, the UIManagedDocument may or may not work—I have not found the circumstances that determine this, yet.
I am pretty sure that the code is correct, as it's actually one of the code examples in the CS193p course from Stanford. The whole example can be downloaded at their website under
http://www.stanford.edu/class/cs193p/cgi-bin/drupal/
Direct link to the code:
http://www.stanford.edu/class/cs193p/cgi-bin/drupal/system/files/sample_code/Photomania_0.zip
Additionally, the code runs fine on the device itself, without generating the "surprising" message, and running all the code that comes afterwards just fine.
I have not found anything on Google, neither on the Apple Developer pages. Restarting the simulator, or XCode, or reinstalling both of them does not change the behaviour.
Any ideas?
I can only say that I've had this happen to me several times. For me, I'm lazy after I update my dataModel and so far, each time I've gotten this error it was because I had changed my data model. Usually, all I need to do is delete my app from the simulator and re-run it and it has always turned out fine. Hope this helps someone out there.
I think I have found the answer. It looks like the automatic saving for UIManagedDocument kicks in only after a few seconds on the simulator.
So I minimized the app on the simulator, by pressing the home button, and then clicked on the icon to maximize it again. And then I terminated the app in simulator.
When I re-launched the app, the database was loaded. The error still shows up - it comes because the document is in "closed" state (that's normal - that's why CS193P asked to call openWithCompletionHandler), but my data across launches is preserved. Unfortunately I have to do the minimize/maximize routine before terminating the app, or the changes are discarded at next launch.
Can you verify that this is the behavior you are able to recreate? At least for testing purposes this should be a good enough trick to use.
Try upgrading to the latest iOS 5.1. I don't think UIManagedDocument with iCloud works reliably in 5.0. This has been my experience.
I love the Stanford iTunes class. However, I think the sample code for using UIManagedDocument is wrong. In fact, he notes in the demo that he is only doing it that way because he wants to just fetch the information right then. In the code comments, he says not to use the auto-save features because the data will not be saved if the app quits. however, UIManagedDocument will save anything that's necessary before quitting. It has all pertinent handlers for quitting/multitasking/etc to make sure the data is saved.
So, if you are using that code as your example, here's a version that should work, and does not use saveToURL (I don't have a flickr account, so I didn't actually run it - but this is how the class is designed to work). Please let me know if it does not work.
- (void)fetchFlickrDataIntoDocument:(UIManagedDocument *)document
{
NSManagedObjectContext *ctx = [[NSManagedObjectContext alloc] initWithConcurrencyType: NSPrivateQueueConcurrencyType];
ctx.parentContext = document.managedObjectContext;
[ctx performBlock:^{
NSArray *photos = [FlickrFetcher recentGeoreferencedPhotos];
for (NSDictionary *flickrInfo in photos) {
[Photo photoWithFlickrInfo:flickrInfo inManagedObjectContext:ctx];
// Push changes to document MOC
[ctx save:0]; // propagates changes to parent MOC
// and tell the document it is dirty and needs to be saved
// It will be saved when the document decides its time to save
// but it *will* be saved.
[document updateChangeCount:UIDocumentChangeDone]
}
}];
}
Still had errors when the last path component for document file url was #"Database". Adding an extension #"Database.db" seems to have fixed it, everything running fine now. Have also upgraded to Lion though.
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
url = [url URLByAppendingPathComponent:#"Database.db"];