Programmatically check whether an app is installed - objective-c

I would like to know whether there is a Swift equivalent of the following Objective-C code
NSURL *appURL = [NSURL URLWithString: #"myapp://"];
if ([app canOpenURL: appURL] {
NSLog(#"The app is this URL Scheme is installed on the device");
}

Before reading this answer you must solemnly swear not to do any of the activities on the page you linked to. (Looking for dating apps? Seriously?)
The method is essentially the same:
if let appURL = NSURL(string: "myapp://test/url/") {
let canOpen = UIApplication.sharedApplication().canOpenURL(appURL)
println("Can open \"\(appURL)\": \(canOpen)")
}

let we take two app with name A and B.
Now i want to open app B from app A, so for that first create URLSchema in app B.
Than add below code to info.plist file in app A.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>app b schema Name</string>
</array>
Now add below code to app A from where you want to open app B.
UIApplication.shared.canOpenURL(URL(string:"app b schema Name://")! as URL)
thank you.

Related

AVCaptureDevice requestAccessForMediaType:

MacOS 10.14
<key>NSMicrophoneUsageDescription</key>
<string>Record audio!</string>
This works in a swift project:
AVCaptureDevice.requestAccess(for: .audio) { granted in
if granted {
//self.setupCaptureSession()
}
}
But this does not work in an ObjectiveC project (Thread 8: signal SIGABRT)
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) {
if (granted) {
//self.microphoneConsentState = PrivacyConsentStateGranted;
}
else {
//self.microphoneConsentState = PrivacyConsentStateDenied;
}
}];
What have I done wrong or missed in the ObjectiveC project? (I don't want to convert my project to swift.)
Any help appreciated. Thanks, paul
In Order to use the AVCaptureDevice you need to add the description for both items i.e NSCameraUsageDescription, NSMicrophoneUsageDescription
For Reference Please see the Apple Doc
If you only want to record the Audio you can also use the AVAudioSession API.
I began a new ObjectiveC project (MacOs 10.14) and copied everything from the old project to it (xibs etc). It displayed the appropriate access dialogue but didn't actually record. Had to check the audio input checkbox in capabilities - after messing about for an hour. :-)

How to access Camera, Calendar, Photos, Microphone, Location, Media Library, Motion, Speech Recognition, SiriKit, TV Provider in iOS 10

I am developing my app for iOS 10, but my default iOS functionality extensions not working well. Like am not able to access camera, Microphone and media Library. Every time it got crashed. I have written all, but nothing working.
case .Authorized:
picker!.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
if UIDevice.currentDevice().userInterfaceIdiom == .Phone
{
self.presentViewController(picker!, animated: true, completion: nil)
}
break
//handle authorized status
case .Denied, .Restricted :
print("Denied")
let alertController = UIAlertController (title: appName, message: "Go to Settings?", preferredStyle: .Alert)
let settingsAction = UIAlertAction(title: "Settings", style: .Default) { (_) -> Void in
let settingsUrl = NSURL(string: UIApplicationOpenSettingsURLString)
if let url = settingsUrl {
UIApplication.sharedApplication().openURL(url)
}
}
let cancelAction = UIAlertAction(title: "Cancel", style: .Default, handler: nil)
alertController.addAction(settingsAction)
alertController.addAction(cancelAction)
presentViewController(alertController, animated: true, completion: nil)
break
A significant change in iOS 10 is that you must declare ahead of time any access to private data or your App will crash. The fix is quick but easy to overlook if the usage is not a major feature of an App so here is your reminder if you are planning an iOS 10 migration.
Don’t Forget Your Purpose Strings
Once you link with iOS 10 you must declare access to any user private data types. You do this by adding a usage key to your app’s Info.plist together with a purpose string. The list of frameworks that count as private data is a long one:
Contacts, Calendar, Reminders, Photos, Bluetooth Sharing, Microphone, Camera, Location, Health, HomeKit, Media Library, Motion, CallKit, Speech Recognition, SiriKit, TV Provider.
If you are using one of these frameworks and fail to declare the usage your app will crash when it first makes the access. The crash log helpfully tells you which key you are missing. For example, this is the result of accessing the camera without adding the key to Info.plist:
This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app’s Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.
To avoid the crash we need to add the suggested key to ‘Info.plist’ (Xcode 8 already contains the full list of possible keys):
The system shows the purpose string when asking the user to allow access (so you may want to localize it):
The direction from Apple is clear. If you access private data declare your intentions up front or expect your App to crash.
You can check all privacy settings key for apple documentation : Privacy setting keys for iOS10

show deviceId on MobileFirst application

I can download logs file via analytics console > Devices > Device Search > Device Information > Download Logs
we can search the logs file by deviceId.
My question is How to know the deviceid from the user ??
For example, there is some problem on the application, the user reports to the admin, and the admin searchs the user device by deviceId.
Is there a code to display deviceId on my application, so the user can send the deviceId to the admin ??
Of course, there is a JavaScript API to get the Device ID.
See WL.Device.getID()
I have seen folks use code like this in Native apps and have some special view to show it t the user
NSUUID *oNSUUID = [[UIDevice currentDevice] identifierForVendor];
or
import android.provider.Settings.Secure;
private String android_id =
Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID);
I have not found an example of this API in JavaScript, but it is very easy to pass the data up from native, for example
in main.m
#import "WL.h"
NSDictionary *data = #{#"id": oNSUUID};
[[WL sharedInstance] sendActionToJS:#"DeviceInfo"
withData:data];
in your app
//global
var nativeInfo = null;
// in wlCommonInit()
var actionReceiver = function(received){
WL.Logger.error(received);
if ( received.action == "DeviceInfo"){
nativeInfo = received.data;
}
};
WL.App.addActionReceiver ("GarantiActionReceiver", actionReceiver);

Current Location doesn't work with Apple Maps IOS 6

Before IOS 6, I was using this URL scheme to open the native maps app and find directions from the users current location to an address that I created.
http://maps.google.com/maps?daddr=" + address + "&saddr=Current+Location
This was working great, but now that they got rid google maps with IOS 6, we had to check which IOS version they were on and then refer them to the new apple maps url scheme if they were using IOS 6.0 or greater. The new url scheme we are using is this....
http://maps.apple.com/maps?daddr=" + address + "&saddr=Current+Location
This is based on the new documentation for map url schemes, which can be found here..
Anyways, I've tested it a bunch and it boils down to the new apple maps does recognize Current Location, like google maps did.
Does anyone know how I fix this?
Keep in mind I am building a html app with phone gap, so using native code to set the starting address to current location won't help me.
I am having the same problem. I haven't found a solution yet but if you leave off the saddr
http://maps.apple.com/maps?daddr=" + address
it will just ask them where to start and the first option is "Current Location" so when they click "Current Location" it will show the map correctly.
If anyone finds a better solution please post it as I am still looking for a better solution.
You can use my method:
<script type="text/javascript">
var link = "maps:saddr=YPlat,YPlong&daddr=42.118599,-72.625122";
navigator.geolocation.getCurrentPosition(showPosition);
function showPosition(position)
{
link = link.replace("YPlat",position.coords.latitude);
link = link.replace("YPlong",position.coords.longitude);
window.location = link;
}
</script>
confirmed with iOS 5.1 and iOS 6
Just pass "Current Location" as the source address:
http://maps.apple.com/maps?saddr=Current%20Location&daddr=Your_Address
You can get the coordinates of the current location using CLLocationManager, or its wrapper DKLocationManager (on github), created by Keith Pitt.
Once you have the coordinates, you can use the following code sample.
+ (void) openDirectionFrom:CLLocation* currentLocation To:(NSString*) daddr {
NSString* urlStr;
NSString* saddr = #"Current+Location";
if ([[UIDevice currentDevice] systemVersion] floatValue] >=6) {
//iOS 6+, Should use map.apple.com. Current Location doesn't work in iOS 6 . Must provide the coordinate.
if ((currentLocation.coordinate.latitude != kCLLocationCoordinate2DInvalid.latitude) && (currentLocation.coordinate.longitude != kCLLocationCoordinate2DInvalid.longitude)) {
//Valid location.
saddr = [NSString stringWithFormat:#"%f,%f", currentLocation.coordinate.latitude,currentLocation.coordinate.longitude];
urlStr = [NSString stringWithFormat:#"http://maps.apple.com/maps?saddr=%#&daddr=%#", saddr, daddr];
} else {
//Invalid location. Location Service disabled.
urlStr = [NSString stringWithFormat:#"http://maps.apple.com/maps?daddr=%#", daddr];
}
} else {
// < iOS 6. Use maps.google.com
urlStr = [NSString stringWithFormat:#"http://maps.google.com/maps?saddr=%#&daddr=%#", saddr, daddr];
}
[(UIApplicationWithEvents*)[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
}

The persistancy on my UIPasteboard is still active when the app is uninstalled. why?

I use the UIPasteboard class to use data with severals app. The doc say that the persistancy is removed when the creator application is uninstalled. I do two app, one for copy, the other for past:
creator app:
-(IBAction)paste:(id)sender{
UIPasteboard* pb = [UIPasteboard pasteboardWithName:#"mytext" create:YES];
tv_pasting.text = pb.string;
}
reader app:
-(IBAction)copy:(id)sender{
UIPasteboard* pb = [UIPasteboard pasteboardWithName:#"mytext" create:YES];
pb.persistent = YES;
pb.string = tf_copy.text;
}
I do a text copy in my first app, I paste on my second app, the text is copied, all is good. After, I uninstall my two app and reinstall the reader app. I do paste... and the older copy is still available. Why ?
After some tests, I found that It removed the UIPasteBoard if the name of it has a link with the bundle identifier of the App.
So if my bundle identifier is
com.test.MyTestApp
the UIPasteBoard name should be
#"com.test.MyTestApp.MyPasteBoard"
Then it will be removed. This is what testing taught me.