Making App default handler on OSX 10.10 with sandbox enabled - objective-c

I wasn't able to find anything online about this, but LSSetDefaultHandlerForURLScheme will return -54 when the sandbox is enabled. I'm not sure what entitlement needs to be turned on for this to work as it does without the sandbox on.
To see this in effect, create a new project with this in the appdelegate:
-(void)applicationWillFinishLaunching:(NSNotification *)notification {
// Become default handler
CFStringRef bundleID = (CFStringRef)CFBridgingRetain([[NSBundle mainBundle] bundleIdentifier]);
OSStatus result = LSSetDefaultHandlerForURLScheme(CFSTR("maxel"), bundleID);
if (result != 0) {
assert(0);
}
}
It will work. Next turn on sandbox. It will fail with -54 in result.
Built on OSX 10.10 Yosemite. Anyone else run into this?

According to Apple's developer forums, you can't do this anymore in the sandbox--the behavior you are seeing is expected. It's really aggravating, because no alternative API exists to implement this functionality, short of stepping outside of the sandbox.

Related

Universal links does not work with React Native

I've been using React Native & Branch.io successfully for awhile and it's great. However, I would like to be able to handle non-Branch deeplinks as well. For instance, if my domain name is https://example.com, I'd like my app to be opened when opening, say, https://example.com/my-items. I've been trying to make it work with no luck. I read many, many GitHub issues and SO questions. To repeat, https://example.app.link (i.e. Branch urls/universal links) work without any issues.
Basically, when I click on https://example.com/my-items , my website opens in Safari. The "Open with XYZ" iOS modal does not show up, and I am not taken to the app.
Here's what I've already tried:
0) Went through https://facebook.github.io/react-native/docs/linking and https://hackernoon.com/react-native-deep-linking-for-ios-and-android-d33abfba7ef3
1) Made sure I serve https://example.com/apple-app-site-association (and verified it with https://branch.io/resources/aasa-validator/ ) as JSON and is publicly available.
2)
2.1) I also tried with app.link associated d
3) For the sake of debugging, I even made the following in AppDelegate.m (normally I check via [RCTLinkingManager application:application openURL:url options:options] etc)
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
return YES;
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
return YES;
}
4) I tried on the device itself (using iMessages, Notes, Safari). I also turned off remote debugging (as noted here)
Relevant versions:
XCode: Version 10.2.1 (10E1001)
iOS: 12.4.1
react-native: 0.60.5
react-native-branch: 3.0.0^
https://example.com/apple-app-site-association
{
"applinks": {
"apps": [],
"details": [
{
"appID": "<MyTeamID-censored>.<My-Bundle-Identifier-censored>",
"paths": [
"/verify-email*",
"/notifications/borrower-request*",
"/notifications/request-confirmed*",
"/messages/*",
"/verification",
"/my-items",
"/my-rentals",
"/dashboard*"
]
}
]
}
}
In Debug mode it not worked for me as well
Try to change build configuration to release(or other if you have) it should work then
Also you can validate your ASAA file online
Is this relevant to your use case? It helped me.
When a user is browsing your website in Safari and they tap a universal link to a URL in the same domain as the current webpage, iOS respects the user’s most likely intent and opens the link in Safari. If the user taps a universal link to a URL in a different domain, iOS opens the link in your app.
source
If you just want to use links with your own domain, then you can change your Branch app.link domain to your own custom domain from Link Settings.

Application.Current.MainPage.DisplayActionSheet causing issue in xamarin.forms IOS

Hello i have implemented camera functionality in my app using media.plugin
but camera does not open in ios.
if (string.IsNullOrEmpty(StorageFolder))
{
StorageFolder = await Application.Current.MainPage.DisplayActionSheet(SystemMessages.PhotoSaveFolder, "Cancel",
null, "folder1", "folder2");
}
await CrossMedia.Current.Initialize();
MediaFile file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
{
});
it is because of DisplayActionSheet() which i use for folder option selection.if i remove that code it works fine.then what is issue with it.cant figure out.
it dont throw any error but thread exit after some time and in debugging i am unable to trace what exactly going on.
please help.stuck with this.
Thank you in advance.
oh..that's the issue of xamarin version. i upgraded xamarin.forms from 2.3.0.107 to 2.3.4.247.that was causing issue.
revert back this changes solved my issue and working well as before.

Calling phone with appcelerator

I'm trying on device make calls but device do not nothing...
This is my code, i'm using Appcelerator 4.4.0.201511241829, IOS 9.2
var dialog = Ti.UI.createAlertDialog({
cancel: 0,
buttonNames: ['Cancel', 'Ok'],
message: "Are you sure?"
});
dialog.addEventListener('click', function(e){
if (e.index !== e.source.cancel){
// IF WE ARE BUILDING FOR DEVELOPMENT PURPOSES - TRY CALLING A FAKE NUMBER
if(ENV_DEV){
Titanium.Platform.openURL('tel:00000000');
}
// ELSE IF WE ARE BUILDING PRODUCTION - THEN USE THE LISTED NUMBER
else if(ENV_PRODUCTION){
Titanium.Platform.openURL('tel:00000000');
}
}
});
dialog.show();
any help?
Your code for call a number seems correct. I suppose that nothing happen because ENV_DEV and ENV_PRODUCTION variables are not True, and so the two if statements are not satisfy.
First of all I suggest you to add an else statement for be sure that one one condition is satisfy. You can modify your code like this:
// IF WE ARE BUILDING FOR DEVELOPMENT PURPOSES - TRY CALLING A FAKE NUMBER
if(ENV_DEV){
Titanium.Platform.openURL('tel:00000000');
}
// ELSE IF WE ARE BUILDING PRODUCTION - THEN USE THE LISTED NUMBER
else if(ENV_PRODUCTION){
Titanium.Platform.openURL('tel:00000000');
}else{
Titanium.Platform.openURL('tel:00000000');
}
Secondly you can add a console log like this Ti.API.info("yourMsg") in each statements to check in which if you are.
I hope this is helpful
Your 'dial a number' code indeed seems correct. I would like to suggest you to structure your code a bit different, I'll give you an example from a recent project of mine.
You can configure phone numbers for your different environments(prod, dev) in your config.json(assuming you are working on an Alloy project, and not a Classic Titanium project), an example:
{
"global": {
"phoneNumber": tel:0032499001122"
},
"env:development": {
"phoneNumber": tel:0111111"
},
"env:test": {},
"env:production": {}, ..
This reduces the code in your click-handler to:
if (e.index !== e.source.cancel){
Ti.Platform.openURL(Alloy.CFG.phoneNumber);
}
Because you pass the environment when you start the application, you do not longer need to check the environment in your code.
Don't forget to add your environment flag(-D development) if you run your app via the CLI, eg.
titanium build -p ios -T simulator -D development

MCSession multipeer in background

I am sending through multi peer in ios7 a file using this method:
_progressSend = [session sendResourceAtURL:imageUrl withName: info toPeer:peerID withCompletionHandler:^(NSError *error) {
// Implement this block to know when the sending resource transfer completes and if there is an error.
if (error) {
NSLog(#"Send resource to peer [%#] completed with Error [%#]", peerID.displayName, error);
}
else {
// Create an image transcript for this received image resource
}
}];
The problem is very strange. This is what happens:
The device starts sending the resource, the progress bar starts filling up. When I put the app in the background, and check my email for example, the transfer is still going on (I can see that from the progress bar of the other device). If the transfer has finished, and I go back in the app, everything works just fine, but if I enter the app while the resource is still being transferred (for e.g. I exit 1/3 of the way and open it at 2/3) the app freezes completely and needs to be closed from the multitask bar. But Xcode doesn't show a crash. It is as iff the app keeps running but the user interface is just totally frozen. Does anyone have an idea??
Have you tried wrapping your code that sends the data in a dispatch_async block?
That might help.
Also how do you get the imageurl? Maybe it somehow can't be read when leaving and then re-entring you app
I had this issue also in a different type of way. On the portion of code that updates the progress bar you need to make it call the main thead by putting the code inside this block:
dispatch_async(dispatch_get_main_queue(), ^{
//insert progress bar code here
});
I don't know why this happens but this seems to have fixed it for me.

How do I allow downloads from a WebView using the standard download system on a Mac app?

I am building a mac app and would like to able to include the ability to browse the web and download files from the sites using the standard downloads system like you see when using safari.
At the moment when I click a link to a .zip or .nzb in the app it does nothing! Is there a way of allowing this from the app?
Thanks in advance for any help :)
The download manager in Safari is implemented by Safari, not by WebKit, so you don't get that functionality "for free", just the tools to build it.
In order to be able to download files, you need to assign an object as the WebPolicyDelegate of the WebView and implement the webView:decidePolicyForMIMEType:request:frame:decisionListener: delegate method.
In that method, you must call one of the WebPolicyDecisionListener protocol methods on the object that is passed as the decisionlistener parameter to the method. The three WebPolicyDecisionListener protocol methods are ignore, use or download. For any MIME types that you want to download, you must call download on the object passed as the listener parameter:
- (void)webView:(WebView *)webView
decidePolicyForMIMEType:(NSString *)type
request:(NSURLRequest *)request
frame:(WebFrame *)frame
decisionListener:(id < WebPolicyDecisionListener >)listener
{
if([type isEqualToString:#"application/zip"])
{
[listener download];
}
//just ignore all other types; the default behaviour will be used
}
You then need to assign an object as the download delegate of your WebView. This object will be sent all of the NSURLDownloadDelegate protocol messages as well as the WebDownload
delegate messages. You can use these messages to choose where the file is downloaded, as well as to implement a download manager UI like Safari.
Off the top of my head I would think you could implement the WebView's delegates to detect when a user clicks on a link - then check the extension and if it's not html/php/whatever then manually download the file yourself
Here's a link to a question (and answer) for how to capture the link pressing:
Cocoa WebKit/WebView delegate for location change? (User clicked link, javascript action, etc)
Another option is to open the link in external browser. And the file will be downloaded using external browser's download manager.
Sample code in Swift 2.2 with XCode 7.3:
func webView(webView: WebView!, decidePolicyForNavigationAction actionInformation: [NSObject : AnyObject]!, request: NSURLRequest!, frame: WebFrame!, decisionListener listener: WebPolicyDecisionListener!) {
let url = request.URL!.absoluteString
if url.hasSuffix(".zip") || url.hasSuffix(".nzb") {
listener.ignore()
NSWorkspace.sharedWorkspace().openURL(request.URL!)
} else {
listener.use()
}
}
PS. method above comes from WebPolicyDelegate.