I am trying a simple sample app on XPCServices, in which I am following below steps:
Step 1: Created a sample project and added target - XPCServices with name - HelperProcess to it. When the target is created XCode automatically generates below files:
HelperProcessProtocol.h
HelperProcess.h
HelperProcess.m
main.m
Step 2: In main.m added a log statement within implementation of ServiceDelegate:
- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
// This method is where the NSXPCListener configures, accepts, and resumes a new incoming NSXPCConnection.
NSLog(#"Log which is never displayed :(");
// Configure the connection.
// First, set the interface that the exported object implements.
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:#protocol(HelperProcessProtocol)];
// Next, set the object that the connection exports. All messages sent on the connection to this service will be sent to the exported object to handle. The connection retains the exported object.
HelperProcess *exportedObject = [HelperProcess new];
newConnection.exportedObject = exportedObject;
// Resuming the connection allows the system to deliver more incoming messages.
[newConnection resume];
// Returning YES from this method tells the system that you have accepted this connection. If you want to reject the connection for some reason, call -invalidate on the connection and return NO.
return YES;
}
Step 3: In AppDelegate added below code in applicationDidFinishLaunching:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
_connectionToService = [[NSXPCConnection alloc] initWithServiceName:#"HelperProcess"];
_connectionToService.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:#protocol(HelperProcessProtocol)];
[_connectionToService resume];
}
Problem is -
When I launch the app, neither the log added in
listener:shouldAcceptNewConnection: is displayed nor the helper
process appears in Activity Monitor :(
Here is the code: XPCShootOut
Note: I am trying this on XCode 6.0
Is there any additional setup which I need to do to make it working? Please suggest.
-- Update --
I tried to refer this sample from apple: AppSandboxLoginItemXPCDemo
When I tried to run it on XCode 6, it displayed error message - 'No signing identity found'. Since I don't have registered mac developer account, in build settings for - iDecide and iDecideHelper I changed 'Code Signing Identity' as 'Don't Code Sign'.
I got a warning for each of the targets:
Code Sign warning: CODE_SIGN_ENTITLEMENTS specified without specifying CODE_SIGN_IDENTITY. It is not possible to add entitlements to a binary without signing it.
This time when I compiled the build, it worked as expected.
Now I tried to follow the steps specified in its ReadMe.txt file, specifically I performed these steps in my sample app:
Step 1: Updated - Main App Target -> Capabilities Tab
Turned on 'App Sandbox'
Turned on 'App Groups'
Added an app group - 'XYZ'
Step 2: Updated - Helper Target -> Capabilities Tab
Turned on 'App Sandbox'
Enabled 'Outgoing Connections (Client)'
Turned on 'App Groups'
Added an app group - 'XYZ'
Step 3: Updated - Helper Target -> General Tab -> Bundle Identifier, added 'XYZ' prefix to it.
On running the app in console it displayed these messages:
10/12/14 6:27:42.159 PM xpcd[554]: (null): Code identity[pid: 11875::Devarshi-Kulshreshtha.XPCShootOut (/Users/devarshi/Library/Developer/Xcode/DerivedData/XPCShootOut-aaedwraccpinnndivoaqkujcmhmj/Build/Products/Debug/XPCShootOut.app)] is not in ACL for container: ~/Library/Containers/Devarshi-Kulshreshtha.XPCShootOut/Data -- allowing access.
10/12/14 6:27:43.712 PM appleeventsd[63]: <rdar://problem/11489077> A sandboxed application with pid 11875, "XPCShootOut" checked in with appleeventsd, but its code signature could not be validated ( either because it was corrupt, or could not be read by appleeventsd ) and so it cannot receive AppleEvents targeted by name, bundle id, or signature. Error=ERROR: #100013 { "NSDescription"="SecCodeCopySigningInformation() returned 100013, -." } (handleMessage()/appleEventsD.cp #2072) client-reqs-q
Neither app performed its intended function nor it displayed the log message added in listener:shouldAcceptNewConnection: delegate.
I am clueless. Kindly suggest if I am missing any thing? Is it possible to get XPC service sample app working without a registered mac developer account?
I don't think you can launch XPC services without having them signed.
Even for testing and debugging the code sign build infrastructure needs to be setup.
I think the Mac developer certificate is free you don't need a paid account for that.
Related
I have cordova based iOS mobile app which need SSL certificate to be embedded with the mobile app & using the AFNetworking plugin to achieve the same.
When I run the build, I am getting the error NSCURLConnection finished with error - code -1003.
Attached the code screenshot.
https://i.stack.imgur.com/Elact.png
Please help.
From the screenshot I'd suggest changing that one line in the if statement as shown below.
if ( ... ) {
manager.securityPolicy.pinnedCertificates = [NSSet setWithObject:localCertificate];
}
Note the warning - you are passing data to an ivar that should get a set.
Then based on the -1003 error - double check the URL that you use. Make sure it is valid and accessible.
EDIT
Also, add the following two lines just before the if statement.
manager.requestSerializer = AFHTTPRequestSerializer.serializer;
manager.responseSerializer = AFHTTPResponseSerializer.serializer;
and see if it helps.
I'm trying to store an struct array into the app group container to use it later on the widget.
let's assume, I have an array of string
let = array = ["object1", "object2", "object3"]
and I saw here I can access to the app group container url
let applicationGroupId = "group.com.development.widget"
guard let groupURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: applicationGroupId) else {
fatalError("could not get shared app group directory.")
}
Now, I need to know how I can store this array on app group and how I can read from it on the Widgetkit SwiftUI class
Your help will be appreciated.
Signing, Capabilities, Entitlements
Right now it should be possible to do all of this from within Xcode (12+). In the app's project settings go to the Signing & Capabilities tab and make sure Automatically manage signing is enabled and the Team has a valid development team (either company or personal account).
Tap on the + Capability button on the top left to enter the App Group Capability (this will also add an entitlements file). Now you will find an App Group section. Hit the + button for App Groups and enter a globally unique identifier (something like group.<appid>). This will create the app group on the developer platform and add it to your app's provisioning profile and entitlements.
You must repeat the same steps and use the same app group for all targets (app target, widget extension target and (optionally) intent targets). If you hit the reload button for the other targets' app group it should automatically show the app group you previously registered and you can check the checkbox. If not, hitting + and using the same id should work as well.
Finally, check all entitlements files and ensure that they have the same String in App Groups (copy and paste just to make sure).
Code
In code you now just have to access the user defaults using the chosen app group as suitName. To test whether everything is set up correctly, I would put the following line in application(_:didFinishLaunchingWithOptions):
UserDefaults(suiteName: "group.id.test")!.setValue(["object1", "object2", "object3"], forKey: "test")
In the Widget just try to put it in a Text view:
struct WidgetTestEntryView : View {
var entry: Provider.Entry
var text: String {
(UserDefaults(suiteName: "group.id.test")!.value(forKey: "test") as? [String])?.joined(separator: " ") ?? "Nothing stored yet"
}
var body: some View {
Text(text)
}
}
Note: I force unwrap the user defaults on purpose to fail early and check whether the setup of capabilities/signing worked. In production you should guard against a failure.
Alternative Storage
As you pointed out it's also possible to persist data in a shared container by writing to url provided by FileManager.default.containerURL(forSecurityApplicationGroupIdentifier:) but I don't think you need that for your simple example. If you want to share data that is more complex than String, Int, Array ... make sure to convert it to Data since user defaults cannot handle arbitrary data (even if it's Codable).
Manual Signing
If you use manual signing you just have to do the same step in the developer console starting with registering an app group. After that, add the group to all identifiers' capabilities and recreate all provisioning profiles. From there you should be use similar steps to the ones described above.
I have a framework that uses
_healthStore requestAuthorizationToShareTypes:writeTypes readTypes:readTypes completion:^(BOOL success, NSError *error) {
When I include the framework into my iOS app and put the following in my app info.plist file
<key>NSHealthShareUsageDescription</key>
<string>Read heart rate monitor data.</string>
<key>NSHealthUpdateUsageDescription</key>
<string>Share workout data with other apps.</string>
everything works fine - not including those keys results in the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSHealthShareUsageDescription must be set in the app's Info.plist in order to request read authorization.'
My problem is that when running the unit tests for the framework it crashes with the above error. I've put the keys in all of the info.plist files for the framework and for the test target but still get the crash.
Which plist file should the keys go into in order to run the test target?
(should also mention that I'm in the process of switching over to Swift3 - this is part of the project that is in Objective-C - prior to iOS10 and XCode 8 this all worked fine).
I've created a framework with appropriate unit test to show the problem: https://github.com/asensei/HKHealthStoreFrameworkUnitTestBug
You must add the NSHealthShareUsageDescription and NSHealthUpdateUsageDescription keys to the Info.plist file in your application. You do this by:
Clicking on the "Info.plist" file
Right clicking the screen and select add rows.
scroll to "Privacy - Health Share.. " and "Privacy - Health Update.. "
Select both of those and you should be good.
You have to add two descriptions NSHealthUpdateUsageDescription and NSHealthShareUsageDescription, and then give each of them a description. See screenshot below.
Can any one help me to figure out the following error I get when I run my application?
Communications error: <OS_xpc_error: <error: 0x10a1abb40> { count = 1,
contents = "XPCErrorDescription" => <string: 0x10a1abef0> { length =
22, contents = "Connection interrupted" } }>
If you are running your app in iOS simulator it uses XPC Services API for interprocess communication and any breakpoint or other interruptions can cause such an error.
You can refer to this Apple Doc
In the section Handling Errors
Interruption handler—called when the process on the other end of the connection has crashed or has otherwise closed its connection.
The debugging of app on device should not have such problems.
I had the same problem when running my app and keyboard extension (I'm building a custom keyboard). Since you do not provide enough information we don't know when this happens to you exactly.. so I'll leave this here in case you are working in an extension too, if not.. hope this will be useful to someone else.
Open the info.plist from your Keyboard Target.
Set Value "Yes" for key "RequestsOpenAccess"
Run your App on device
Go To Settings, General, Keyboard, Keyboards
Select your keyboard
Change "Allow Full Access" to True.
Please pay attention how often you are accessing to the Database.
I also have the same problem. I am working with chat using Firebase. So in my case I made a mistake when I too often get/put data from/into DB.
when I launch my app normally with 3g/wifi on, I get no error within the console. When I disable data access (aka airplane mode) for testing purposes, I get the following error message when the app launches within the console :
2011-11-16 19:17:40.440 Juice[8674:707] Reachability Flag Status: -- ------- networkStatusForFlags
2011-11-16 19:17:41.292 Juice[8674:707] Applications are expected to have a root view controller at the end of application launch
May it be noted that I get a uialertview that pops up when the app detects no data connection and that I am using a tab bar controller. I have no idea why I am getting these error messages.
Thanks in advance!
Those are not error message per-say, but rather notification messages letting you know that there is no network connection. To disable them you can open up your local copy of Reachability.m and change this:
#define kShouldPrintReachabilityFlags 1
To:
#define kShouldPrintReachabilityFlags 0
The line is just below the #import "Reachability.h" line.
Reachability.m source
Reachability.h source