CarPlay parking app crashed when launching from Xcode 12.5.1 CarPlay simulator - swift

I'm new in iOS development. Got task on job to extend our iOS app with CarPlay. I created class 'CarPlaySceneDelegate' as entry point for Car Play. Code is below:
class CarPlaySceneDelegate: UIResponder, CPTemplateApplicationSceneDelegate {
var interfaceController: CPInterfaceController?
func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene,
didConnect interfaceController: CPInterfaceController) {
self.interfaceController = interfaceController
...
interfaceController.setRootTemplate(tabBarTemplate, animated: true)
}
private func templateApplicationScene(_ templateApplicationScene: CPTemplateApplicationScene,
didDisconnect interfaceController: CPInterfaceController) {
self.interfaceController = nil
}
}
To Info.plist I added this configuration:
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>Configuration Name</key>
<string>Default configuration</string>
<key>Delegate Class Name</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>Storyboard Name</key>
<string>Main</string>
</dict>
</array>
<key>CPTemplateApplicationSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneClassName</key>
<string>CPTemplateApplicationScene</string>
<key>UISceneConfigurationName</key>
<string>BlueGate-Car</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).CarPlaySceneDelegate</string>
</dict>
</array>
</dict>
</dict>
On launching on simulator CarPlay launches good according to CarPlaySceneDelegate class. But on iPhone Simulator it's not launched at all. App loads and screen become black.
In console:
2021-11-03 12:45:11.228204+0200 BlueGate[5806:119147] - <AppMeasurement>[I-ACS036001] Analytics screen reporting is disabled. UIViewController transitions will not be logged.
2021-11-03 10:45:11 +0000 [AppDelegate.swift]:[application(_:didFinishLaunchingWithOptions:)][103:19] start function
2021-11-03 12:45:11.714422+0200 BlueGate[5806:118883] [Firebase/Crashlytics] Version 8.7.0
2021-11-03 12:45:12.108628+0200 BlueGate[5806:119153] 8.7.0 - [Firebase/Analytics][I-ACS023007] Analytics v.8.7.0 started
2021-11-03 12:45:12.119347+0200 BlueGate[5806:119153] 8.7.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://<someLink>)
2021-11-03 12:45:12.140585+0200 BlueGate[5806:119154] 8.7.0 - [Firebase/Analytics][I-ACS025036] App Delegate Proxy is disabled
2021-11-03 10:45:12 +0000 [AppDelegate.swift]:[configureNetworkMonitoring()][89:35] Network is ON
2021-11-03 12:45:12.316632+0200 BlueGate[5806:119154] 8.7.0 - [Firebase/Messaging][I-FCM002022] APNS device token not set before retrieving FCM Token for Sender ID '188981723956'. Notifications to this FCM Token will not be delivered over APNS.Be sure to re-retrieve the FCM token once the APNS device token is set.
2021-11-03 12:45:17.626397+0200 BlueGate[5806:119147] 8.7.0 - [Firebase/Analytics][I-ACS800023] No pending snapshot to activate. SDK name: app_measurement
2021-11-03 12:45:17.735262+0200 BlueGate[5806:119147] 8.7.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled
My environment Xcode 12.5.1
Did I do anything wrong or Is there any other way I can implement the CarPlay part feature by Xcode/swift while keeping the mobile app on iOS?
Appreciate any comments or help.

The keys of your application scene in the plist seem to be wrong. Try using UISceneConfigurationName instead of Configuration Name, UISceneDelegateClassName instead of Delegate Class Name and UILaunchStoryboardName instead of Storyboard Name.

Related

MoPub for iOS: 'Target is not running or required target entitlement is missing'

I'm trying to monetize my app with MoPub for iOS 14, but my ad is not being shown and I get the following messages in the logs when trying to display an ad:
Initialized OM SDK version: 1.3.4-Mopub
Attempting to load ad
[assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing}>
[ProcessSuspension] 0x10b0b8bc0 - ProcessAssertion: Failed to acquire RBS Background assertion 'WebProcess Background Assertion' for process with PID 18829, error: Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing}
SDK initialized and ready to display ads.
Initialized adapters:
No adapters initialized
Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service
Could not signal service com.apple.WebKit.Networking: 113: Could not find specified service
In my AppDelegate's application(_: didFinishLaunchingWithOptions:) function, I have the following:
let sdkConfig = MPMoPubConfiguration(adUnitIdForAppInitialization: "TestAdUnitID")
sdkConfig.loggingLevel = .info
MoPub.sharedInstance().initializeSdk(with: sdkConfig, completion:{
GameViewController().showAd()
})
I have a view controller that adheres to the MPAdViewDelegate protocol and loads the ad like this, after the SDK has finished initializing:
self.moPubBannerView = MPAdView.init(adUnitId: "TestAdUnitID")
let adSize = kMPPresetMaxAdSize50Height
let bounds = view.bounds
var adFrame = CGRect.zero
adFrame.size = CGSize(width: 320, height: 50)
adFrame.origin.x = (bounds.size.width-adFrame.size.width)/2
adFrame.origin.y = bounds.size.height - adFrame.size.height
self.moPubBannerView?.frame = adFrame
self.moPubBannerView?.maxAdSize = adSize
self.moPubBannerView?.delegate = self
self.view.addSubview(self.moPubBannerView!)
self.moPubBannerView?.loadAd()
I have set Privacy - Tracking Usage Description in my info.plist. I'm testing on a real device, using the correct MoPub SDK.
Any idea what could be causing this error, and how to fix it? Thank you for your help!
EDIT:
Initially, I had integrated the MoPub SDK manually -- but I tried integrating using cocoa pods, too, and received the same errors/problems.
EDIT #2:
MoPub responded to my support request by telling me that I need to include an entitlement, without telling me which entitlement I need. So, I know I'm missing an entitlement, I just need to know which one.
EDIT #3:
I tried a different advertisement provider's framework and ran into the same error. So, it must be my problem -- not MoPub's. I tried enabling the Access WiFi Information capability (and confirmed that it was added to my App.entitlements) and I also added App Transport Security Settings -> Allow Arbitrary Loads to my Info.plist. But the problem remains.

Xcode+Swift+XPC: How to start and deploy a Swift XPC target on MacOS

DISCLAIMER: I am relatively new to MacOS/Xcode
I want to build a simple XPC Launch Agent in Swift (ie: in ~/Library/LaunchAgents) but I could not find much documentation.
I started with Xcode XPC template but I do not know if it was a good idea for my Swift project.
I notice I should also have ~/Library/LaunchAgents/com.demo.myservice.plist
Versions:
- MacOS: 10.13.2
- Xcode: 9.2
Instruction to create the Xcode XPC Project:
File > New project
I chose the MacOS template: XPC
I create the bundle ‘com.demo.myservice’
It creates me an Objective-C project. So I delete all files (ie: myserviceProtocol.h, myservice.h, myservice.m, main.m and Info.plist
Create the files:
myserviceProtocol.swift
import Foundation
#objc(myserviceProtocol) protocol myserviceProtocol {
func ping()
}
myservice.swift
import Foundation
class myservice : NSObject, myserviceProtocol {
func ping() {
print("ping")
}
}
main.swift
import Foundation
class ServiceDelegate : NSObject, NSXPCListenerDelegate {
func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool {
newConnection.exportedInterface = NSXPCInterface(with:myserviceProtocol.self)
let exportedObject = myservice()
newConnection.exportedObject = exportedObject
newConnection.resume()
return true
}
}
// Create the listener and resume it:
//
let delegate = ServiceDelegate()
let listener = NSXPCListener.service()
listener.delegate = delegate;
listener.resume()
Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.demo.myservice</string>
<key>ProgramArguments</key>
<array>
<string>myservice</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
I build it:
I copied Info.plist into ~/Library/LaunchAgents/ : cp ~/Documents/myservice/myservice/Info.plist ~/Library/LaunchAgents/com.demo.myservice.plist
I retrieve my userid with id -u
And then I try to execute it from the command line (as it does not seem to do anything from Xcode):
sudo launchctl debug user/501/com.demo.myservice /Users/olivier/Library/Developer/Xcode/DerivedData/myservice-hbwefcgibyqbajguvblgcmxsnrmd/Build/Products/Debug/myservice.xpc
Configuration failed: 113: Could not find specified service
Could not find service "com.demo.myservice" in domain for uid: 501
I am not really sure of what I am doing. Was I right to use XPC template to create my swift XPC.
If you want your Agent to provide an XPC service, you need to expose it as a Mach Service.
The way you are initialising your Listener is for an XPC Service (notice capital S), an XPC Service is a bundle that is part of your application's bundle, located inside the Contents/XPCServices/ directory.
So in summary, you would have to:
1.) Create an Agent that exposes an XPC service via mach service. Your listener would look like:
let listener = NSXPCListener(machServiceName: "com.rderik.exampleXPC" )
2.) To consume your Agent's service you'll need to build the connection to that mach service.
let connection = NSXPCConnection(machServiceName: "com.rderik.exampleXPC")
I hope that helps.
If you want to read more, I wrote a tutorial on how to do that here:
https://rderik.com/blog/creating-a-launch-agent-that-provides-an-xpc-service-on-macos/
I'm not sure what your goal is. If you just want a daemon that is managed by launchd, then you don't need XPC. Just create a daemon (probably with the Command Line Tool project template) and create a launchd plist configuration file (see man launchd.plist).
XPC is intended to communicate with a host app. The service binary should be embedded in your app bundle and launchd will launch it when your app tries to connect. You don't need to modify ~/Library/LaunchAgents for this.
Your app needs to setup an NSXPCConnection to connect to the XPCListener you created.
Something like:
let connection = NSXPCConnection(serviceName: "com.demo.myservice")
let interface = NSXPCInterface(with: myserviceProtocol.self)
connection.remoteObjectInterface = interface
connection.resume()
let proxy = connection.remoteObjectProxyWithErrorHandler {(error) in
os_log("Connection Error: %{public}#", error.localizedDescription)
} as! myserviceProtocol
// message proxy here to communicate with service
Both scenarios are covered in more detail in the Daemons and Services Programming Guide

Bluemix Cordova iOS Push notifications - Don't see device - Internal server error. No devices found

I am trying to get the Bluemix Cordova Hello World sample working with IBMPushNotifications Service. I have installed the cordova plugins and if I run cordova plugin list I see:
ibm-mfp-core 1.0.10 "MFPCore"
ibm-mfp-push 1.0.12 "MFPPush"
My index.js initialization code looks like this:
onDeviceReady: function() {
BMSClient.initialize(app.route, app.guid);
BMSClient.registerAuthenticationListener("MyRealm", customAuthenticationListener);
// alert("******** ABOUT TO CALL MFPPush.registerDevice **************");
// MFPPush.registerDevice(iosPushSettings, pushSuccess, pushFailure);
MFPPush.registerDevice({}, pushSuccess, pushFailure);
I do have the MAS customAuthentication service running and working.
I am running the code on an attached iPad via Xcode. I've added some debugPrint statements inside the plugin swift file and see the following messages in the Xcode Console:
"Inside Register Device!!!!!!!"
"Inside registerNotificationsCallback"
"Settings Parameter is not null"
"settings.count == 0"
"about to set notificationSettings"
"About to registerForRemoteNotifications"
"Called registerForRemoteNotifications"
I am not a swift or iOS developer, so I am pretty ignorant on debugging and working with iOS apps. I tried to set breakpoints in the AppDelegate.m file and appears that the code is hitting the breakpoint in didRegisterForRemoteNotificationsWithDeviceToken and I think a token value is getting set. However, I never see my debugPrint code getting triggered in the CDVMFPPush.swift file inside
func didRegisterForRemoteNotifications(deviceToken: NSData) {
debugPrint("Inside didRegisterForRemoteNotifications")
or inside
func didFailToRegisterForRemoteNotifications(error: NSError) {
debugPrint("Inside didFailToRegisterForRemoteNotifications")
As far as I can tell, I have set up the APNS Cert and provisioning profile and I have uploaded my sandboxAPNS.p12 file without any errors into my Bluemix Push service.
On the Bluemix Push Dashboard, if I try to send a push notification to all devices, I receive the following error:
Internal server error. No devices found
I also see PushNotifications enabled in the capabilities tab for my app in XCode.
I am trying to determine why I never see my debugPrint statements for the didRegister or didFailToRegister and why Bluemix does not see my device. Thanks for any suggestions on how to debug and again my apologies for my ignorance on swift and XCode.
JT
OK, I got Push notifications working. It turns out I needed to modify the AppDelegate.m file as per the docs and the Git readme:
// Register device token with Bluemix Push Notification Service
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
[[CDVMFPPush sharedInstance] didRegisterForRemoteNotifications:deviceToken];
}
// Handle error when failed to register device token with APNs
- (void)application:(UIApplication*)application
didFailToRegisterForRemoteNotificationsWithError:(NSError*)error {
[[CDVMFPPush sharedInstance] didFailToRegisterForRemoteNotifications:error];
}
// Handle receiving a remote notification
-(void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[[CDVMFPPush sharedInstance] didReceiveRemoteNotification:userInfo];
}

Get Zookeeper started automatically in OS X Yosemite using launchd

Like the title said, I'm trying to launch zookeeper automatically using launchd/launchctl in OS X Yosemite.
This is my plist file "/Library/LaunchDaemons/com.test.zookeeper.plist", it's owned by root:wheel.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.test.zookeeper</string>
<key>RunAtLoad</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/opt/zookeeper/bin/zkServer.sh</string>
<string>start</string>
</array>
<key>StandardInPath</key>
<string>/var/log/zookeeper_stdin.log</string>
<key>StandardOutPath</key>
<string>/var/log/zookeeper_stdout.log</string>
<key>StandardErrorPath</key>
<string>/var/log/zookeeper_stderr.log</string>
</dict>
</plist>
after executing "sudo launchctl load com.test.zookeeper.plist",
this is what's in the "/var/log/system.log", user name has been replaced with asterisks.
Apr 17 11:13:22 ***-03 sudo[97284]: ****.** : TTY=ttys003 ; PWD=/Library/LaunchDaemons ; USER=root ; COMMAND=/bin/launchctl load com.test.zookeeper.plist
Apr 17 11:13:22 ***-03 com.apple.xpc.launchd[1] (com.apple.xpc.launchd.domain.system): Session adoption is only allowed in user domains.
Apr 17 11:13:22 ***-03 nohup[97299]: Could not adopt Background session: 125: Domain does not support specified action
"/var/log/zookeeper_stdout.log"
Starting zookeeper ... STARTED
"/var/log/zookeeper_stderr.log"
JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
So it seems like the job was executed by launchd, but somehow the actual service is not present when I execute "ps -ef | grep zoo" to check for the service, which I would normally see if I started zookeeper manually using "sudo /opt/zookeeper/bin/zkServer.sh start"
Can someone help me? Thank you.
I had a simple ping being run by launchd and I would get
Session adoption is only allowed in user domains.
in the system log -- and the process would not run.
My guess is it gets blocked due to that issue in the log.
If you do launchctl list |grepplist name and it shows - in the first column (which is supposed to be a PID), then the job never ran.
Below, is an example of a working plist running a bash script.
# launchctl list |grep ping
549 0 com.pingServers

iOS Dropbox Datastore API: WebKit Exception + Unsupported URL

(Note, this seems related to this question, but is with a different flavor of the Dropbox SDK.)
Using the latest version of the Dropbox Datastore API on iOS, I am getting an exception after performing these steps:
Successfully connect my app to Dropbox
Disconnect my app from Dropbox.
Reconnect app to same, or another, Dropbox account.
Then this happens:
The console in Xcode shows this:
*** WebKit discarded an uncaught exception in the webView:
decidePolicyForNavigationAction:request:frame:decisionListener:
delegate: <NSInvalidArgumentException> -[PilotPro.SettingsTableViewController
dropboxWasLinked:]: unrecognized selector sent to instance 0x7fc489cb94d0
And then this:
[WARNING] DropboxSDK: error loading DBConnectController - Error
Domain=NSURLErrorDomain Code=-1002 "unsupported URL"
UserInfo=0x7fc48c11bc50 {NSUnderlyingError=0x7fc48c4418c0 "unsupported URL",
NSErrorFailingURLStringKey=db-***://1/connect?
oauth_token_secret=***&state=***&oauth_token=***&uid=***,
NSErrorFailingURLKey=db-***://1/connect?
oauth_token_secret=***&state=***&oauth_token=***&uid=***,
NSLocalizedDescription=unsupported URL}
I suspect I am not doing enough to disconnect Dropbox from my account, so it's conflicting with a Dropbox session somehow. Here's what I'm doing to disconnect:
//===::: Disable Dropbox :::===
DBAccountManager.sharedManager().linkedAccount.unlink()
// Shutdown and stop listening for changes to the datastores
DBDatastoreManager.sharedManager().shutDown()
DBDatastoreManager.sharedManager().removeObserver(self)
//Migrate back to local datastores
DBDatastoreManager.setSharedManager(DBDatastoreManager.localManagerForAccountManager(DBAccountManager.sharedManager()))
Any ideas? Thanks in advance.
It turns out that the errors given by Xcode were a bit of a red herring in this case. I was firing an NSNotification after Dropbox finished authenticating, and in doing so I was using this:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "dropboxWasLinked:", name: "dropboxLinked", object: nil)
...but my dropboxWasLinked method wasn't set up to receive any arguments:
func dropboxWasLinked(){ ... }
So Xcode was firing an exception that messed up the authentication and made other things appear to be the cause, when in reality all I needed to do was remove the : from my selector in the NSNotification listener.
Ah, the joys of programming. :)