Launch watch kit app from within another watch kit app - watchkit

I know on the phone it is possible to launch an application from within another using something along the lines of...
-(IBAction) openYoutube:(id)sender {
UIApplication *ourApplication = [UIApplication sharedApplication];
NSString *ourPath = #"http://www.youtube.com/watch?v=TFFkK2SmPg4";
NSURL *ourURL = [NSURL URLWithString:ourPath];
[ourApplication openURL:ourURL];
}
This will launch the youtube app
My research hasn't led to anything useful and I doubt there is something out there, but what's the harm in asking to be sure. Is there anyway to accomplish this sort of functionality from the apple watch? Like if the user hits a button, I want my watch kit app to launch the instagram or twitter watch kit app

Fortunately, you can. You can ask the iOS app to do this. Use this method
[WKInterfaceController openParentApplication:#{[results firstObject]:[results firstObject]} reply:^(NSDictionary *replyInfo, NSError *error) {
}];
To call your parent iOS app. Within the iOS app, implement this delegate method to achieve what you want (in your AppDelegate).
(void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply{}

Related

Xamarin.Forms for iOS using SceneDelegate.cs

In iOS 13, UIScene is used. Codes in AppDelegate.cs must be moved into SceneDelegate.cs to support multiple windows of the same app in Split View.
For Xamarin.Forms, AppDelegate.cs uses LoadApplication (new App()) to launch an instance of App.cs in the Xamarin.Forms. LoadApplication is found in Xamarin.Forms.Platform.iOS.FormsApplicationDelegate.
What is the equivalent in SceneDelegate.cs to launch an instance of App.cs in the Xamarin.Forms?
From the app lifecycle of xamrin forms :
iOS – Main method > AppDelegate > App > ContentPage .
Android – MainActivity > App > ContentPage
We will see that Main method invoke App class before , if need a instance of App from iOS , generally will try as follow :
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App(app)); // pass app to Forms
return base.FinishedLaunching(app, options);
}
However ,Forms can not using UIKit (error screenshot).
In xamarin forms , there is DependencyService to load navtive method . Therefore, suggest that using DependecyService to call app from iOS native AppDelegate.cs .
About using SceneDelegate.cs in Xamarin Forms , there is no SceneDelegate.cs file in iOS solution now . I will check that whether be possible in Xamarin Forms .
==================================Update==============================
If want to deal with a universal link in AppDelegate.cs , you need to do something in continueUserActivity method as follow :
public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler)
{
//return base.ContinueUserActivity(application, userActivity, completionHandler);
if(userActivity.ActivityType == NSUserActivityType.BrowsingWeb)
{
NSUrl url = userActivity.WebPageUrl;
// other code
}
return true;
}
==================================Update===============================
Finally , found that it is possible to add SceneDelegate to a Xamarin Forms project. A new Xamarin Forms project does not come with the necessary SceneDelegate.cs or .storyboard files, so these need to be added. After adding these files, the info.plist needs to be updated with the UIApplicationSceneManifest key, which will contain more needed keys.
The additions to info.plist are shown here: https://learn.microsoft.com/en-us/xamarin/ios/platform/ios13/multi-window-ipad#project-configuration (just UIApplicationSceneManifest and everything under)
The two things to note are that:
The sample has issues with navigation working properly when having multiple windows of the app running.
This is not an official sample, as Xamarin.Forms does not currently offer official support for using mutiple Scenes with an iOS application.
The unofficial Xamarin.Forms sample is here:https://www.dropbox.com/s/sdxq5me7vcdmuf9/XamFormsiOSMultiWindow.rar?dl=0
It seems this issue has been resolved in MAUI. Just inherit from MauiUISceneDelegate for your SceneDelegate class and the framework will take car of the rest:
[Register("SceneDelegate")]
public class SceneDelegate : MauiUISceneDelegate
{
}
And then in your info.plist file:
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>__MAUI_DEFAULT_SCENE_CONFIGURATION__</string>
<key>UISceneDelegateClassName</key>
<string>SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
I wish there was an equally clean solution for Xamarin.Forms as we have not migrated our app to MAUI yet.
Hope this helps!
*Update:
Junior Jiang's solution did work for me, but I had to make a few changes to get it to work:
Uncomment the following lines in SceneDelegate.cs:
//var ad = new AppDelegate();
//ad.GetUI();
...
//Window.RootViewController = ad.Window.RootViewController;
Then add the following line after the uncommented code in SceneDelegate.cs
Window.MakeKeyAndVisible();
I made a few additional changes that are not specifically required, but probably a bit better in terms of resource usage, such as rather resolving appDeleggate as follows:
var appDelegate = (AppDelegate)UIApplication.SharedApplication.Delegate;
And instead returning the created Xamarin.Forms app in GetUI method (in AppDelegate) to be used in SceneDelegate, instead of creating another one in SceneDelegate.
One limitation that I did notice is that I could no longer see iOS alert messages, so I used a custom syncfusion popup instead.

How do you test Firebase Dynamic Links in Unity?

Based on the Firebase Unity documentation, you only need to add Firebase Dynamic Links SDK and then listen for incoming links like this in order to capture Dynamic links:
void Start()
{
DynamicLinks.DynamicLinkReceived += OnDynamicLink;
}
// Display the dynamic link received by the application.
void OnDynamicLink(object sender, EventArgs args)
{
var dynamicLinkEventArgs = args as ReceivedDynamicLinkEventArgs;
Debug.LogFormat("Received dynamic link {0}", dynamicLinkEventArgs.ReceivedDynamicLink.Url.OriginalString);
}
The dynamic link I have previously generated, correctly redirects me to the Google play store where my app exists. When I click on "open" from the play store, my app opens on the device but dynamic link information is not passed at all.
Do I need to create a new alpha version of my app to test this on Play Store?
Some people in Stackoverflow mentioned about Alpha version, but those people don't have an app released, whereas I do.
Also, is there way to test this in Unity editor?
I still need to write the code to parse it and it's kind of ridiculous to blindly code this.
If you are still testing and don't want to release a version with Dynamic Links to production, you can release your build which has Dynamic Links to a beta release so you can be sure it's working as expected.
Otherwise, releasing to production also will work.
The build you are installing from play store needs to have the Dynamic Links library and also the codes anyway.

BackgroundUploader for Xamarin.Forms C#

I am working on converting my WindowsPhone project to Xamarin.Forms project.
I had a BackgroundUploader task for uploading my video files to server in background. However, I am not able to find a similar class in Xamarin Forms that does the same job.
Below is my BackgroundUploader code for WindowsPhone project.
Any kind suggestions please.
BackgroundUploader bguploader = new BackgroundUploader();
bguploader.SetRequestHeader(RequestHeader, jsonConverter.Serialize(Video));
UploadOperation upload = bguploader.CreateUpload(new Uri(url), videoFile);
Progress<UploadOperation> callback = new Progress<UploadOperation>(UploadProgress);
await upload.StartAsync().AsTask(canceltoken.Token, callback);
This is definitely a OS-specific functionality and it has no built-in solution in Xamarin.Forms.
As you mentioned BackgroundUploader is the solution working for UWP and Windows Phone.
For some info on iOS background execution check out the documentation. You will probably use NSURLSessionUploadTask.
On Android you should look into Background Services. See Android documentation.
To implement this in a cross-platform manner, you will have to create a shared interface and then provide platform-specific implementations. See Xamarin.Forms DependencyService for more details.

Make QR Code to Open Android Application? [duplicate]

2 questions about using a QR code in an Android device:
1. Is it possible to launch a native Android application from a QR code? Maybe by some configured URI schema?
2. Another option which might be useful for me is to have a QR code scanner inside my own app. Will it be possible for me to somehow include a different app that scans QR codes inside my app? Or will I have to implement the scanning myself?
Thanks
To scan barcodes in Android by Intent, see https://github.com/zxing/zxing/wiki/Scanning-Via-Intent
To trigger an app from a QR code, yes, you need to register the app to handle the particular custom URL scheme. This is how the same app can respond to clicks on the web: https://github.com/zxing/zxing/wiki/Scanning-From-Web-Pages
Look at how it registers to handle URLs here: https://github.com/zxing/zxing/blob/master/android/AndroidManifest.xml
1.to use a configured schema you can check this post
Launch custom android application from android browser
Then the you could QR code this scheme just like market://
2. You could use Bar code scanner app and use below code to launch or you could even integrate the zxing library to scan yourself.
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE",
"ONE_D_MODE,QR_CODE_MODE,PRODUCT_MODE,DATA_MATRIX_MODE");
startActivityForResult(intent, 0);

Firefox webapp file input

I'm developing a webapp for firefox aurora (android). And i have an file input.
But when users click on the input they can't choose files from sdcard or filesystem only pictures, music or videos.
I search at MOZILLA DEVELOPER NETWORK, but couldn't find anything helpful.
In my manifest.webbapp i have device-storage permission:
"permissions": {
"device-storage:sdcard":{ "access": "readonly" }
},
I assume you are currently simply using the markup ?
The device-storage:sdcard is for a very different set of use cases really. And we don't have that implemented on Firefox for Android yet.
The list of applications being shown is just the set of applications that we're getting from the Android Intents system. I would imagine that if the user has some sort of filebrowser app installed it might respond to that intent and it'd pop up there.
But of course that's not something you can rely on in your app.
I'm honestly somewhat surprised that there's no default applications on android that provide that functionality, but I guess that's how it is. Or does someone know of a way to also get a filepicker intent that we can hook up to?
Medium term you will be able to use the DeviceStorage API. This will give you direct JS access to the sdcard which will allow you to build your own UI for choosing a file from the SD card. But that extra power comes with quite a few downsides. It's a privileged API which means that you'll have to write the app as a packaged app and you have to use CSP. And you'll have to go through the Firefox marketplace review process (all privileged apps have to go through code review).
So it's a pretty distant second choice.
Other than that there aren't any solutions. The best would of course be if there was a way we could plopp up an Android file picker, but I'm not sure if that's doable. And it's definitely not implemented yet.
According to the source code, this permission is only granted to apps that are packaged and privileged, the latter also means the app has to be signed by the Marketplace.
You can find more about packaged apps and privileged app types here:
https://developer.mozilla.org/en-US/docs/Apps/Packaged_apps
Just install an Android file manager app (https://play.google.com/store/search?q=file+manager&c=apps) and you will be able to select files from the SD card. There is no need for specific rights because this is handled automatically by the standard file input.
Accessing the SD Card can only be achieved through a privileged or certified app. Currently to my knowledge, there is no integration the system menus as you are hoping would be the case. Personally, I'm hoping that this will change.
API Documentation: https://developer.mozilla.org/en-US/docs/WebAPI/Device_Storage
You could create your own menu that mimics the the system one; in this way the user gets a seamless experience and they don't know the difference. It would require a little boilerplate though it's not insurmountable levels of boilerplate.
A quick snippet for browsing/enumerating all photos on the the SDCard:
var storage = navigator.getDeviceStorage("sdcard");
sdcard.browse = function () {
var pics = navigator.getDeviceStorage('pictures');
// Let's browse all the images available
var cursor = pics.enumerate();
cursor.onsuccess = function () {
var file = this.result;
alert("File found: " + file.name);
// Once we found a file we check if there are other results
if (!this.done) {
// Then we move to the next result, which call the cursor
// success with the next file as result.
this.continue();
}
}
cursor.onerror = function () {
alert("No files found: " + this.error);
}
};
If you would like some more details for reading, writing, and caulating available storage, I'm currently working on a little wrapper library in my spare time to work with the SDCard more easily (and handle some callbacks to integrate better with other code) in my spare time and can probably help you out.

Resources