My didFinishLaunchingWithOptions method stores a filename from the UIApplicationLaunchOptionsURLKey and tries to open it.
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL* url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
NSError* err;
if ([url checkResourcesIsReachableAndReturnError:&err])
{
...
}
}
For iOS 8 this code works fine. My application is launched because some other application selected "open in" to my application, but for iOS 9 this code doesn't work, and I get
err = NSCocoaErrorDomain : code 257 : "The file 'XXX' couldn't be
opened because you don't have permission to view it."
"The operation couldn't be completed. Operation not permitted"
Very important note: This only happens when my application was shut down while the user tried to open a file from another application. I see that the file that is being sent in UIApplicationLaunchOptionsURLKey is indeed located not in the same sandbox as my application is. If it was not shut down, just minimized, everything behaves well because the UIApplicationLaunchOptionsURLKey is in the same sandbox.
This was a problem in iOS 9 beta 3 that was resolved in beta 4.
didFinishLaunchingWithOptions method was triggered with a filepath in the UIApplicationLaunchOptionsURLKey that was in a different application's space, hence it was sandboxed and the iOS application could not access it.
Anyhow Apple now resolved this issue.
Related
I have an app built that uses the UIDocumentBrowser. It was working fine until I tried to add an ImagePickerController to allow the app to use the camera and take photos. The Documents folder is now no where to be found on the "Files" app or in the app I am developing. I could find it in the Finder on the Mac I am using for developing the app.
I tried deleting the entire app and data and installing a cleaned build.
I have this sitting at the top of the app launch method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
_datapath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
if (![NSFileManager.defaultManager fileExistsAtPath:_datapath])
[NSFileManager.defaultManager createDirectoryAtPath:_datapath withIntermediateDirectories:YES attributes:nil error:nil];
When I run it in debug, it finds the already created documents folder so skips over the createDirectoryAtPath method.
Any ideas what's happening and/or how I can fix it?
Note: I never got to the point in the app where I could test the ImagePicker before this problem happened and removing the code I added didn't fix the problem.
Must have been cached information. Powered down the iPad and restarted fixed the problem.
I tried to implement universal links in my application, but it's not working. I uploaded the apple-app-site-association file to my server, i can access it.
(MIME type: application/json)
Here is the content of the apple-app-site-association file:
{
"applinks": {
"apps": [],
"details": [
{
"appID": "L7LAMSGWAK.com.example.app",
"paths": [
"*"
]
} ]
}
}
I turned on the Associated domains in my application, and i added these domains:
applinks:example.com
applinks:demo.example.com
(i uploaded the apple-app-site-association file to the demo.example.com domain too)
In the AppDelegate.m file i wrote this:
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler {
NSURL* openedUrl = userActivity.webpageURL;
NSString* urlString = [openedUrl.absoluteString lowercaseString];
return YES;
}
And i set a breakpoint into this method to check if its called, but its never called. If i click on for example this link: https://demo.example.com/asd its just open the safari, but i never see the banner to open the link in my application. I really dont know whats wrong.
Try to delete and reinstall the app. iOS processes associated domain details and attempts to read the apple-app-site-association file at app install. It worth trying it with a real device (instead of the Simulator) and check device logs (Xcode > Window > Devices and select your device). If you see anything like ### Rejecting URL 'https://demo.example.com/apple-app-site-association' for auth method 'NSURLAuthenticationMethodServerTrust': -6754/0xFFFFE59E kAuthenticationErr, then probably your site's certificate is not good enough for iOS or there is some other issue with downloading your association file.
Kind of a late answer, but I had the same problem when I was trying to implement universal links. The solution for me was to test using a real device.
The Apple documentation lists that it's possible to test on a simulator, but with my own experience, it hasn't been possible.
You can test universal links in Simulator or on a device. Source - Apple
I also tried using Branch.io and they state that it's not possible to test using a simulator.
You should also verify that you're using a device that's running iOS >= 9.2
I created a WatchKit Application with the default XCode Template.
I added an app group entitlement to the iOS Target, to the Watchkit App Target and to the Watchkit App Extension Target. (this is the app group name: group.com.lombax.fiveminutes)
Then, I tried to access the shared folder URL with both the iOS App and the WatchKit Extension:
Extension:
#implementation ExtensionDelegate
- (void)applicationDidFinishLaunching {
// Perform any final initialization of your application.
NSURL *test = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:#"group.com.lombax.fiveminutes"];
}
iOS App:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
NSURL *test = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:#"group.com.lombax.fiveminutes"];
// ...
}
However, the test NSURL is different:
On iOS:
file:///Users/Lombardo/Library/Developer/CoreSimulator/Devices/38B983DB-342F-4A47-8C26-5D2C92CDB666/data/Containers/Shared/AppGroup/8DEE182E-AFE6-47DD-BA2B-6B0520158A8B/
on Watch:
file:///Users/Lombardo/Library/Developer/CoreSimulator/Devices/BF52D613-25FF-4092-A5B2-9C3F1B616160/data/Containers/Shared/AppGroup/CECB5EFC-7FBD-4C84-A878-1314CB7CF211/
And for this reason I'm unable to share data between the iOS App and the WatchKit Extension.
I cannon try on a real device since I don't have WatchOS 2.0 on my Apple Watch.
Any advice?
Thanks
UPDATE
I did some other tests:
Installed WatchOS 2, the issue still persists on real devices.
This is the store url for my iPhone:
NSURL
* #"file:///private/var/mobile/Containers/Shared/AppGroup/3D05D159-94D6-409C-9A38-90E0830D0C3F/FiveMinutes.sqlite"
And this is the store url for my Watch:
NSURL
* #"file:///private/var/mobile/Containers/Shared/AppGroup/F1E89377-F456-4FC2-BAAC-3DD705EF381A/FiveMinutes.sqlite"
The two apps reads and write to-from two different .sqlite files.
On simulator, if I hard-code one of the URLs, both iOS simulator and Watch simulator are able to read-write the same .sqlite file and share the content. However, this is not possible on real devices since the Watch extension cannot write to the iOS path:
URL:file:///private/var/mobile/Containers/Shared/AppGroup/3D05D159-94D6-409C-9A38-90E0830D0C3F/FiveMinutes.sqlite options:(null) ... returned error Error Domain=NSCocoaErrorDomain Code=512 "The file couldn’t be saved." UserInfo={reason=Failed to create file; code = 2} with userInfo dictionary {
reason = "Failed to create file; code = 2";
}
Ok, I think I've found my answer. I remembered that with the transition to Watch OS 2 the extension code is now executed directly on the Apple Watch, and no more on the paired iPhone. So it's seems obvious that the two devices doesn't share the same storage.
The first thing I did was to create a new project, starting from a base iOS Project, and then adding a Watch OS 1 (old version) App Target.
In this case, the directories were identical and they could communicate:
Watch Path: file:///Users/Lombardo/Library/Developer/CoreSimulator/Devices/BF52D613-25FF-4092-A5B2-9C3F1B616160/data/Containers/Shared/AppGroup/30B39103-CEEB-4C64-9531-FB27DC40180D/
iOS Path file:///Users/Lombardo/Library/Developer/CoreSimulator/Devices/BF52D613-25FF-4092-A5B2-9C3F1B616160/data/Containers/Shared/AppGroup/30B39103-CEEB-4C64-9531-FB27DC40180D/
Then, I did the first thing every programmer should do: read the docs.
In the FIRST PAGE of the WatchOS 2 transition guide there is this sentence:
Your extension now stores files and data on Apple Watch. Any data that is not part of your Watch app or WatchKit extension bundle must be fetched from the network or from the companion iOS app running on the user’s iPhone. You cannot rely on a shared group container to exchange files with your iOS app. Fetching files involves transferring them wirelessly to Apple Watch.
first time user of PLCrashReporter. I have written the code in my appDelegate.m file
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
NSLog(#"inside applicationdidfinishlaunching to do crash reporting");
PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];
NSError *error;
if ([crashReporter hasPendingCrashReport])
[self handleCrashReport];
if (![crashReporter enableCrashReporterAndReturnError:&error])
NSLog(#"Warning: Could not enable crash reporter %#",error);
}
I wrote handleCrashReport as it is in the example. I also on purpose crashed my app on clicking a button.(NSRangeException index 0 beyond bounds for empty array) like this:
NSMutableArray *mtestArray = [NSMutableArray new];
NSLog(#"%#",[mtestArray objectAtIndex:0]);
It throws exception (i.e. goes to main.m file. Doesn't go to home screen. It stays on the main.m file). I stop the execution and restart the app and it goes to a screen (this screen occurs if it were correct actually). I dont see a pop up saying send crash report or don't. I added CrashReporter.framework and libcrashreporter-iphonesimulator.a to my project. I changed mach-o and perfom single...as told in the article. I have been at this for more than 2 hours. Why dont i see the error dialog?
I put breakpoints at my applicationdidfinishlaunching and they NEVER get hit. I deleted my app and reinstalled (re-run) and still no go. Also my project is an iPad project with iOS 6.1. I read that crash report dialog appears on second time start of the app. But it won't any time,2nd or 3rd. If you need more information, please ask. Thanks
EDIT : Does plcrash reporter work for iPads also? I took the help from this blogpost
http://mandeepdhiman.blogspot.com/2011/10/crash-reporter-for-ios.html
I am testing applications on device, I used bundle identifier "mycompany.app" and after selecting proper code signing i am able to run the application on device(i.e my iPhone).
Now after successfully run this application I deleted that and used the same bundleId and provisioning to test other application which is of local notifications. so it start showing the badge number on the application Icon whenever the local notification generated.
Now again I deleted this application and try running my previous application with same bundle but it is showing the badge Number (ie 1) on application Icon even though I have not added any code for showing the badge Number to this application. How to remove these badge?
Hi please use following code in
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
function:-
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;