GCDWebServer: Unable to open home page when using real iPhone - ios

I have an old app using GCDWebUploader of GCDWebServer to upload files into the app. And I copy the implementation code into a new project.
The problem: in this new project, the home page of GCDWebServer could be opened in iOS Simulator but cannot connect in real iPhone.
Environment:
Xcode 12.2, iOS 14
CocoaPods
It is weird since I got a worked app already. So I did some checks:
first, old app is worked. Means the home page could be opened.
all devices are under same wifi.
try to open http://192.168.1.5/ or http://192.168.1.5:80 in browser, safari said "Cannot open the page, because the server isn't responding", however I could ping 192.168.1.5 in terminal successfully.
restart my iPhone
compare info.plist between two projects
No result! Would you guys advice about what I missed, maybe some config in Xcode to allow HTTP communication or some capabilities to enable?
What in console:
[DEBUG] Did open IPv4 listening socket 3
[DEBUG] Did open IPv6 listening socket 4
[INFO] GCDWebUploader started on port 80 and reachable at http://192.168.1.5/
Visit http://192.168.1.5/ in your web browser
The code:
import GCDWebServer
import Foundation
class MyWebUploader {
// move webuploader to outside of init func to fix app crash issue.
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
lazy var webUploader = GCDWebUploader(uploadDirectory: self.documentsPath)
func initWebUploader() -> String {
var ipAddress = String()
webUploader.start()
webUploader.allowedFileExtensions = ["mp3", "aac", "m4a", "wav"]
if webUploader.serverURL != nil {
// retrieve IP address from URL
let str = webUploader.serverURL!.absoluteString
let start = str.index(str.startIndex, offsetBy: 7)
let end = str.index(str.endIndex, offsetBy: -1)
let range = start..<end
let mySubstring = str[range]
ipAddress = String(mySubstring)
print("Visit \(webUploader.serverURL!) in your web browser")
} else {
ipAddress = "No Wifi connected"
}
return ipAddress
}
func stopWebUploader() {
webUploader.stop()
}
}

This issue is caused by the new permission in iOS 14 to find and connect to devices on your local network.
To fix it, we need to add following info in info.plist
<key>NSLocalNetworkUsageDescription</key>
<string>Reason for using Bonjour that the user can understand</string>
<key>NSBonjourServices</key>
<array>
<string>_http._tcp</string>
<string>_http._udp</string>
</array>
More details please see NSNetServiceBrowser did not search with error -72008 on iOS 14

Related

Spotlight search not working for mac catalyst apps

I've an iOS app that has spotlight search feature which allows user to search items from an app. It works fine on iOS app
I am in the process of migrating the app as a catalyst app, somehow the spotlight search on mac catalyst app is not working
So far following things have been checked
Spotlight search logic is working as expected, there are no errors
Restarted Mac
Open catalyst app multiple times just to check if it is syncing with core spotlight and it is.
No previous issues registered on stack-overflow
Env: macOS 12.0.1
P.S: I am unsure if it is related to specific to my code as it is working fine on iPad and iPhone devices.
let attributeSet = CSSearchableItemAttributeSet(contentType: .content)
attributeSet.title = decodeItem.name
attributeSet.relatedUniqueIdentifier = decodeItem.id
attributeSet.url = URL.init(string: decodeItem.url)
let searchableItem = CSSearchableItem(uniqueIdentifier: decodeItem.id,
domainIdentifier: "com.xxx.xxxx",
attributeSet: attributeSet)
searchableItems.append(searchableItem)
CSSearchableIndex.default().indexSearchableItems(searchableItems) { error in
if let error = error {
print("Issue indexing: \(error)")
} else {
print("Indexed.")
}
}
Found the issue: Assign value to attributeSet.relatedUniqueIdentifier only from initializer

Local Firebase remote config plist can't be read when launching without app internet

I have problems with firebase remote config reading from local .plist file (default values provided in case if user has no internet connection when fetching remote config values on first app open).
This happens ONLY when launching app in offline mode.
Just to update:
file name is 100% correct. Checked many times.
checked plist file - maybe corrupted or something with terminal command: plutil PATH - all good.
Currently setup:
When initialising remote config service:
let settings = RemoteConfigSettings()
settings.minimumFetchInterval = 0
RemoteConfig.remoteConfig().setDefaults(fromPlist: remoteConfigDefaults)
RemoteConfig.remoteConfig().configSettings = settings
Then trying to read array value:
func arrayValue(forKey key: RemoteConfigKey) -> [String] {
if localStorage.isRemoteConfigDebugEnabled,
let localValue = localStorage.getRemoteConfigValue(forKey: key) as? String {
return localValue.components(separatedBy: ",")
}
return value(forKey: key).jsonValue as? [String] ?? []
}
and value is:
func value(forKey key: RemoteConfigKey) -> RemoteConfigValue {
RemoteConfig.remoteConfig().configValue(forKey: key.rawValue)
}
The problem actually is only with arrays and strings. Int and booleans works just fine (exactly same method, just instead of jsonValue as [String] used .boolValue or .numberValue.IntValue and .doubleValue.
Was trying to debug for a while. Updated to latest firebase SDK, nothing helped.
Any advice?
So I have digged deeper and found a reason. So in case someone needs the answer and has the same issue:
There were a complex of things that had to be fixed:
Firebase SDK had an issue, that was fixed in 8.0 version, so had to update Firebase sdk
There were wrong quetes used in plist file, so just check that questes are normal.
FirebaseApp.configure() (in my case it was with settings, but nevertheless it is the same) has to be called before setting remote config settings

How to trigger PER-APP-VPN using NEVPNManager class in iOS using Swift4

I need your some efforts, for helping me to resolve this PER-APP-VPN issue.
Problem Statement : My app is unable to invoke PER-APP-VPN, while opening app.
Description :
I've deployed my app on MDM i.e supervised device. Whenever I open my app, it doesn't trigger PER-APP-VPN connection automatically.
What did I tried:
For this I've written below code...this is just I've done for demo purpose. But still not working.
let status=NEVPNManager.shared().connection.status
print(status)
}
let manager = NEVPNManager.shared()
let result = NEOnDemandRuleConnect()
result.interfaceTypeMatch = .any
manager.onDemandRules = [result]
manager.isOnDemandEnabled = true
manager.isEnabled = true
manager.saveToPreferences()
self.vpnStatus.text = manager.connection.status.rawValue == 1 ? "VPN Connected" : "VPN Not Connected"
Scenario:
I've corporate VPN. And I'm deploying app on corporate / work supervised device. I've deployed app on Blackberry EMM Solution.
So, I've assigned PER-APP-VPN profile. But still it is not invoking VPN connection automatically.

App can't access internet connection when connected to LTE

I use reachability to check internet connection when I connect to wifi it works fine. But when its connected to LTE network it gives me No Connection error, even though it is connected, I can browse the internet perfectly with LTE. I have also enabled App Transport Security in info.plist. I'm testing it on ios 10.1.1, do I have to do something to get internet access for my app in ios 10 using LTE?
Guru provided an excellent link in his comment. An updated way to check an LTE connection is indeed through CoreTelephony. Seeing as you asked in Swift though, I'll provide a Swift answer.
Make sure you have CoreTelephony.framework added under your project's Build Phases > Link Binary With Libraries
The code to check the connection in Swift would be as follows
import CoreTelephony // Make sure to import CoreTelephony
let constantValue = 8 // Don't change this
func checkConnection() {
let telephonyInfo = CTTelephonyNetworkInfo()
let currentConnection = telephonyInfo.currentRadioAccessTechnology
// Just a print statement to output the current connection information
print("\(constantValue)==D, Current Connection: \(currentConnection)")
if (currentConnection == CTRadioAccessTechnologyLTE) { // Connected to LTE
} else if(currentConnection == CTRadioAccessTechnologyEdge) { // Connected to EDGE
} else if(currentConnection == CTRadioAccessTechnologyWCDMA){ // Connected to 3G
}
}

Theos inter-app communication using mach ports

I am trying to send data between an App and a console app (using theos) on iOS 8.
I have tried:
Application:
CFMessagePortRef port = CFMessagePortCreateLocal(kCFAllocatorDefault, CFSTR("co.test"), &message_callback, NULL, NULL);
This works fine. NSLog(#"%#", port) returns:
<CFMessagePort 0x17018bef0 [0x198094f50]>{locked = Maybe, valid = Yes, remote = No, name = co.test, source = 0x0, callout = message_callback (0x1000e979c), context = <CFMessagePort context 0x0>}
However when trying to do the same thing on the console app:
CFMessagePortRef port = CFMessagePortCreateLocal(kCFAllocatorDefault, CFSTR("co.test"),
&message_callback, NULL, NULL);
I always get the error:
*** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0xc03, name = 'co.test'
Even though I am using the same com.apple.security.application-groups entitlement for both:
<key>com.apple.security.application-groups</key>
<array>
<string>co.test</string>
</array>
Can anyone shed any light - maybe the above is a terrible approach and I am missing an easier way to accomplish my goal?
My goal is to be able to pass a NSDictionary between an app running on SpringBoard and a daemon built with theos.
Note: I have no intention of distributing this app on the app store
Application: .......CFSTR("co.test")
Console App: ... CFSTR("co.test")
You need to append an additional string to the end of your application group identifier.
Apple:
Mach port names must begin with the application group identifier, followed by a period (.), followed by a name of your choosing.
For example, if your application group’s name is Z123456789.com.example.app-group, you might create a Mach port named Z123456789.com.example.app-group.Port_of_Kobe.
CFMessagePort and sandboxing
Another crash seems to occur if you create multiple Message Ports use the same Message Port Name. Perhaps from an app with the same bundle ID or some other situation in which there should only be a single Message Port and one is already running.
I notice it when I run one version of my macOS app from /Applications/, and another via Xcode.
*** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0xcd07, name = 'XXXYYYZZZZ.MyAppGroupName'

Resources