How to open Main App withe parameters in a helper app? - cocoa

There is a helper app for my Project, both main App and helper app are in sandbox. The main App may be not running so i can not post distributed notification in helper App. And i found that helper App has no permission to set Userdefaults of main App.
So the only thing i can do is to open main App in the helper App with a parameter.
I can use below to do this.
[[NSWorkspace sharedWorkspace]launchAppWithBundleIdentifier:#"com.mainApp" options:0 additionalEventParamDescriptor:nil launchIdentifier:nil];
So how can i pass and get the parameter between the two apps?

Use app groups, so both apps will share access to special container (with a settings plist file for example).

Related

How To Change Client Configuration In XCode Simulator For Automated UI Testing

After writing UI tests with XCTest, I'm trying to change the server the build points to in the Settings app in the simulator. This is so automated tests run in the right place. Is there a way to do this with accessibility and UI testing code?
How can I change this URL?
Edit: #oletha 's answer is perfect. Here's the solution I used in Objective-C:
I set the launch argument to be configServer=#"URL"
for (NSString *launchArgument in [[NSProcessInfo processInfo] arguments]) { if ([launchArgument hasPrefix:#"configServer"]) { return [launchArgument componentsSeparatedByString:#"="].lastObject; } }
You can send a launch argument to the app by setting the launchArguments property before launching the app. You can then set up your app to read the launch argument during launch and set the URL of your mock server when it is launched with that launch argument.
// test code
let app = XCUIApplication()
app.launchArguments = ["UITESTS"]
app.launch()
// app code
if NSProcessInfo.processInfo().arguments.contains("UITESTS") {
// set different server URL
}
You probably want to add the URL switching code in applicationDidFinishLaunching on your app delegate.
As per Xcode 8.2 you cannot automate UI outside your own app's target, so you cannot interact with the Settings app on the device. I feel this is a bug and filed a radar (http://www.openradar.me/27802551), you might want to do the same.
I imagine the URL you're trying to change is stored somewhere in your preferences. If that's the case you could change it dynamically during the execution of your tests using SBTUITestTunnel. This is a 3rd party library that allows to interact with your application from UI Tests, enabling network mocking and monitoring, data injection and more. For your use case it allows to easily update NSUserDefaults.

XPCServices not updating the code

I create project for os x application with xpcservices that run by loginItems. that's mean the service is founded in the app in the path:{APP_NAME}.app/Contents/Library/LoginItems
and who is responsible for run the service is the the main app:
NSXPCConnection *connection = [[NSXPCConnection alloc] initWithLoginItemName:#"{SERVICE_NAME}.app" error:&error];
I used the class :NSXPCConnection+LoginItem.h from apple's docs example :
https://developer.apple.com/library/mac/samplecode/AppSandboxLoginItemXPCDemo/Listings/iDecide_NSXPCConnection_LoginItem_h.html
Q:
Why when I update the service code (even just logs) it's not changed?
you should know:
I deleted all the files that related to this projects and service
( I don't used LaunchAgents or LaunchDaemons folders)
I did remove the service by: launchctl remove {SERVICE_LABLE}
I used the Console App for seeing the difference between the version that I'm running
I even bought "cleanMyMac3.app" and did restart and still I run from Xcode the app and still show logs from previous version.
I searched file on the system that related to the service name, and I find few folders that created and I deleted them:
~/Library/Group Containers/{SERVICE_NAME}
~/Library/Containers/{SERVICE_NAME}
~/Library/Caches/{SERVICE_NAME}
~/Library/Saved Application State/{SERVICE_NAME}
I'm not work sandbox
Do you reference the service (XPC service) properly?
i.e. (as per Apples Example)
`NSXPCConnection *connection = [[NSXPCConnection alloc] initWithLoginItemName:#"XYZABC1234.com.example.iDecideHelper.app" error:&error];`
Also as this example is pretty old, if you traverse the XPC requirements you'll notice that some changes need to be made:
Both the containing project (the iOS or OSX App) and the XPC service App ned to be sandboxed
Ideally, the XPC service should be named as: com.theMainApp.identifier.com.whateverServiceName.
So in the Apple example you've listed IDecideHelpers identifier would be: com.example.iDecide.WhateverServiceName. iDecide (the main app) would be com.example.iDecide

Webview not showing loaded content

I'm trying to experiment with web view by using swift. I created a simple Xcode project, placed a web view within my application interface and connected it to my app delegate.swift with an outlet called "myview". By executing
self.myview.mainFrameURL = "http://www.google.com"
from within applicationDidFinishLaunching(), I would expect the Google's homePage to be loaded. However, this doesn't happen: the web view does not show anything. What am I doing wrong?
1) Add the NSAppTransportSecurity in your plist https://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/
2) check in your project settings that "Sandbox" is enabled and that internet connections are allowed
You will have to call loadRequest() to make it load a page.
So basically:
[self.myWebView loadRequest: [NSURLRequest requestWithURL:
[NSURL URLWithString: #"http://www.google.com"]]]
After digging into the console logs, I found the solution to my problem. I'm not sure if I can share it though, since I'm using a beta OS X version and this restriction could have been introduced to improve apps' security, even if from what I can see it can be disabled.

Parse.com not working on OSX (Swift)

I am trying to use Parse.com SDK in my Mac OSX app written in swift. I have followed the Quickstart Guide and used a bridging header but when I launch the app I am shown this message and the object is not created on launch.
Failed to set (contentViewController) user defined inspected property on (NSWindow): You have to call setApplicationId:clientKey: on Parse to configure Parse.
Any Ideas?
Thanks
I just ran into the same issue, for some reason the viewDidLoad() on the view controllers are executing before the app delegate's applicationDidFinishLaunching: method.
Although Parse recommends having their methods setup in the app delegate, setting up the app id/client key on your initial view's viewDidLoad will let you use parse normally.

sandbox :get NSData using bookmarkDataWithOptions method of NSURL without NSOpenPanel

I enabled sandbox and I want to create data by bookmarkDataWithOptions.
If the URL is created by NSPanel that work very well. But, If I obtain URL without using NSOpenPanel, the bookmarkDataWithOptions method always return nil. why?
thank about If I want to set a special folder default can read/write without using NSOpenPanel.
How can i do?
Thanks
The main feature of the Sandbox is security. If an application could read/write an arbitrary folder without user permission, the security would be broken.
The App Sandbox Design Guide states clearly:
• Simulation of user input in Open and Save dialogs:
if your app depends on programmatically manipulating Open or Save dialogs to simulate or alter user input, your app is unsuitable for sandboxing.
The only way to achieve something similar, is to add a read/write entitlement to one of the preset directories (Documents, Pictures, Music, etc…). For further documentation, take a look at this guide.

Resources