I'm making an iOS app for jailbroken devices running iOS 12 with Swift.
Recently I made a question, which I answered myself, in which I asked for a way to run command line tasks with Swift in iOS.
But as you can see, I'm not done yet as I'm able to use NSTask, but it crashes while running the app.
Basically, I have a NSTask.h file that allows me to use NSTask with Swift.
So, to launch a task I made the following function:
func task(launchPath: String, arguments: String...) {
let task = NSTask.init()
task?.setLaunchPath(launchPath)
task?.arguments = arguments
// Create a Pipe and make the task
// put all the output there
let pipe = Pipe()
task?.standardOutput = pipe
// Launch the task
task?.launch()
task?.waitUntilExit()
}
And call the function like this:
task(launchPath: "/usr/bin", arguments: "git clone https://github.com/lz4/lz4.git")
The problem is that when I run the app, it crashes and prints the following error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't posix_spawn: error 13'
What can I do to fix this error?
Thanks in advance.
EDIT: By the way, I forgot to mention I access the NSTask.h file using Bridging Headers.
The launch path must be the full path of the executable, not the directory containing the executable. Also the command arguments should be provided as separate arguments, not as one string. (Note that there is no shell involved which parses the command and separates the arguments before starting the process.) Therefore the call should be something like
task(launchPath: "/usr/bin/git", arguments: "clone", "https://github.com/lz4/lz4.git")
Related
Using Xcode 12.4 Simulator 14.4
For the alert displayed below, I have the following function in my XCUITests that I use to pull the static text displayed on the System Alert:
_ = addUIInterruptionMonitor(withDescription: "", handler: { (alert) -> Bool in
var data = alert.staticTexts.allElementsBoundByIndex.map {$0.label}
...
})
This worked when using Xcode 11.3 Sims 13.3; however, I just upgraded Xcode and now it crashes on when running the map function and gives the following error:
error: Execution was interrupted, reason: internal ObjC exception breakpoint(-8)..The process has been returned to the state before expression evaluation.
If I put a breakpoint, I can see the following:
po alert.staticTexts.allElementsBoundByIndex.count -> returns 3
po alert.staticTexts.allElementsBoundByIndex[0].label -> returns "Allow “X” to use your location?"
po alert.staticTexts.allElementsBoundByIndex[1].label -> returns "Your location is used to find and display nearby X facilities."
po alert.staticTexts.allElementsBoundByIndex[2] -> returns StaticText, {{32.0, 12.0}, {72.5, 16.0}}, label: 'Precise: On'
However, when I run the following (or runs during my test), it fails but as you can see from above, it does have a static text element at that position:
po alert.staticTexts.allElementsBoundByIndex[2].label -> No matches found for Element at index 2 from input {(
StaticText)} error: Execution was interrupted, reason: internal ObjC exception breakpoint(-8)
If I remain in the console and rerun the same call again, it then works though:
po alert.staticTexts.allElementsBoundByIndex[2].label -> "Precise: On"
Does anyone know what causes this error or a solution for how I can handle it in my test?
As this alert is "outside" your application and everything works when you debug/pause execution, I have to think this is something to do with synchronization.
Do you have anything waiting for the alert to fully display? I don't usually trust the UIInterruptionHandler to do more than auto-dismiss an alert not under test.
I'm using a page object model and typically wait for new pages in the initializer using something like _ = XCUIApplication().alerts.firstMatch.waitForExistence(timeout: 2.0)
That doesn't explain why your example of calling it twice in the console works, but timing is where I'd be looking. I feel that's the only time I ever see errors like this.
It could also be related to the map not being static or loading slowly and therefore changing the accessibility after XCUITest thinks it has finished loading and proceeds. Throwing in a nice long Thread.sleep would be the easiest way to debug that.
I made a game in Unity, and built it for iOS devices. The clients asked if we could implement WebTrends into the game, and so I followed this getting started guide for instructions on how to install it.
I was able to set it up, and got to Step 5, which suggests the following:
Lifecycle events can be logged automatically by setting the
wt_dc_automatics_enabled config setting to true
This is where I got stumped. I then added the above setting to my webtrends.plist, so it now looks like this:
When attempting to build and run that, I get an error in Xcode, and the game refuses to run:
Uncaught exception: NSInvalidArgumentException: -[__NSCFBoolean hasPrefix:]: unrecognized selector sent to instance 0x11294d238
This guide suggests setting wt_dc_enabled to true instead of wt_dc_automatics_enabled.
But even after replacing that in the plist, it returns the same error.
Notably, the project runs fine if I remove the wt_dc_automatics_enabled / wt_dc_enabled from the plist file, though it doesn't sent any logs, to my knowledge.
Is there anything else I can do?
Can you trying making wt_dc_automatics_enabled as String type and not boolean type and add its value as YES.
Because your error says somewhere in the code hasPrefix method is called on Boolean value. hasPrefix method is defined in String class and there is no such method in Boolean class.
I recently started to get this error (detailed error below) in my iOS mobile app built using react-native. This only happens when I try to run the app on the phone by using Option 2 which is to load using a static bundle. I have tried:
Clean and rebuild in Xcode
Reset cache and run react packager
Uninstall the app on the phone
Coming from Windows background, I have also tried to reboot my machine
Error in Xcode
2016-08-04 09:34:37.611 GalarmApp[367:165469] *** Assertion failure in
-[RCTBatchedBridge loadSource:](), /Users/abc/Projects/GalarmApp/node_modules/react-native/React/Base/RCTBatchedBridge.m:180 2016-08-04 09:34:37.613 GalarmApp[367:165469] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'bundleURL must be non-nil when not implementing loadSourceForBridge'
*** First throw call stack: (0x182b32db0 0x182197f80 0x182b32c80 0x1834b81c0 0x1000af788 0x1000adefc 0x1000adca4 0x1000e73d8 0x1000e7368 0x1000e6700 0x1000e643c 0x10005a254 0x10003cebc 0x10003c214 0x10003966c 0x100039b18 0x187d069c0 0x187f36184 0x187f3a5f0 0x187f37764 0x1844d37ac 0x1844d3618 0x1844d39c8 0x182ae909c 0x182ae8b30 0x182ae6830 0x182a10c50 0x187cff94c 0x187cfa088 0x10003bee0 0x1825ae8b8) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
I can see that this problem is printed here in the code but I am a beginner at best in native iOS development and don't know how to fix this problem.
Please help me in fixing this problem. Thanks!
Code in AppDelegate.swift file
/**
* Loading JavaScript code - uncomment the one you want.
*
* OPTION 1
* Load from development server. Start the server from the repository root:
*
* $ npm start
*
* To run on device, change `localhost` to the IP address of your computer
* (you can get this by typing `ifconfig` into the terminal and selecting the
* `inet` value under `en0:`) and make sure your computer and iOS device are
* on the same Wi-Fi network.
*/
// let jsCodeLocation = NSURL(string: "http://localhost:8081/index.ios.bundle?platform=ios&dev=true")
/**
* OPTION 2
* Load from pre-bundled file on disk. The static bundle is automatically
* generated by "Bundle React Native code and images" build step.
*/
let jsCodeLocation = NSBundle.mainBundle().URLForResource("main", withExtension: "jsbundle")
As you can see, I have commented out Option 1 and uncommented out 'Option 2`. I have run the same app this way on the device like 100 times. I have not made any changes to the code but all of a sudden I started to see the error above.
Just to add a quick "doh" moment for me. If you're running in the simulator and get this, make sure the package manager is running when you run your app. If it's not, it could complain about this.
You can also get this error if you are not signing the app correctly. Check the Xcode settings and warnings
For my case, I turn on the web proxy settings on my mac which causes the problem. Turning off web proxy settings resolves my problem.
I'm integrating W3i Advertiser SDK in iOS app, but app is being crashed at following line.
[[W3iAdvertiserSdk sharedConnector] connectWithAppID:W3I_APP_ID];
and here is exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI W3iPublisherJSONRepresentation]: unrecognized selector sent to instance 0xa1d7520'
*** First throw call stack:
(0x29d3012 0x23fae7e 0x2a5e4bd 0x29c2bbc 0x29c294e 0x16af7a 0x3e25 0xcd57b7 0xcd5da7 0xcd6fab 0xce8315 0xce924b 0xcdacf8 0x2903df9 0x2903ad0 0x2948bf5 0x2948962 0x2979bb6 0x2978f44 0x2978e1b 0xcd67da 0xcd865c 0x2d08d 0x26c5)
libc++abi.dylib: terminate called throwing an exception
I Searched a lot but there is no information on net related to w3i's integration and it's use except w3i's official guideline.
https://associate.w3i.com/integration/W3i_iOS_Advertiser_SDK_Integration_Guide1.htm
https://associate.w3i.com/integration/index.html
Here are steps i'm following:
Step1: Download SDK from W3i
Step2: Drag W3iAdvertiserSdk-3.2.0 folder into project's file folder
Step3 Add a link to the following frameworks if not already present:
AdSupport.framework
UIKit.framework
Foundation.framework
CoreGraphics.framework
Step4: Add to your AppDelegate.m file, #import "W3iAdvertiserSdk.h"
If I run the app after above Integration then app runs fine without any error but when i call the method of W3iAdvertiser to connect with app then it it throws exception which i've already posted above.
// add this line to application's didFinishLaunchingWithOptions method
[[W3iAdvertiserSdk sharedConnector] connectWithAppID:W3I_APP_ID]; //appId created at w3i
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI W3iPublisherJSONRepresentation]: unrecognized selector sent to instance 0xa1d7520'
*** First throw call stack:
(0x29d3012 0x23fae7e 0x2a5e4bd 0x29c2bbc 0x29c294e 0x16af7a 0x3e25 0xcd57b7 0xcd5da7 0xcd6fab 0xce8315 0xce924b 0xcdacf8 0x2903df9 0x2903ad0 0x2948bf5 0x2948962 0x2979bb6 0x2978f44 0x2978e1b 0xcd67da 0xcd865c 0x2d08d 0x26c5)
libc++abi.dylib: terminate called throwing an exception
Can anyone please guide me where i'm going wrong, how to use SDK's functions to connect App with w3i's to advertise our app through w3i ?
You need to follow this step as well:
Add -ObjC to Other Linker Flags in your target's Build Settings. That will allow "Option 1" to not crash.
There are two ways to connect app with w3i:
Option1: Integrate W3i-iOS-SDK, and call it's method "connectWithAppId" at start of application.
Option2: Call W3i "appWasRun" API at start of application
first option didn't work for me, but Option2 is quite easy and working fine.
Here is format of API and it's parameters:
http://api.w3i.com/PublicServices/MobileTrackingApiRestV1.svc/AppWasRun?AppId={APPID}&clientIp={CLIENTIP}&iOSIDFA={advertisingIdentifier}&iOSUDID={IOSUDID}&iOSOpenUDID={IOSOpenUDID}&iOSMD5WLANMAC={iOSMD5WLANMAC}&iOSSha1HashedMac={iOSSha1HashedMac}
Request Type: GET
Required Parameters: APPID (generated by W3I) and at-least one identifier (all parameters are preferred by W3i)
I used only OpenUDID and it worked fine.
http://api.w3i.com/PublicServices/MobileTrackingApiRestV1.svc/AppWasRun?AppId=W3i_APP_ID&iOSOpenUDID=OPEN_UDID
For More Information check the following links.
https://sites.google.com/site/w3ideveloperscom/ios/iOSAFPP/advapi
https://associate.w3i.com/integration/Device_Identifiers.htm
Hope it would help others in future :)
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* +[NSString stringWithUTF8String:]: NULL cString'
* First throw call stack:
(0x374ec8bf 0x362cb1e5 0x374ec7b9 0x374ec7db 0x31dade97 0x278f 0x2c2d 0x307877eb 0x307813bd 0x3074f921 0x3074f3bf 0x3074ed2d 0x36000e13 0x374c0553 0x374c04f5 0x374bf343 0x374424dd 0x374423a5 0x30780457 0x3077d743 0x2439 0x23d0)
terminate called throwing an exception
I just don't understand why it was working until 5 minutes ago testing it on the same thing and now it's not working anymore. What can I do to solve this problem? The application works fine on the simulator.
Your string cString = null..
Fill it.
Where do you get the string? One of the more common reasons for "works on Simulator but not device" is that you are reading from a file and use the wrong case -- device has case-sensitive file systems, but Macs have case-insensitive (typically).
The reason why it didn't work on the device is because I modified the database and for some reason the one on the device was the wrong one which obviously was incompatible with the new code. After I deleted the application from the Ipod and then ran it again it worked just fine.
The reason why I had that specific error is because some variables that were holding database columns were empty.