How to Create a Apple Music User Token outside iOS - ios

I am trying to let people like tracks, albums or playlists on Apple Music from a webpage.
I understand the manual on this page:
https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/AppleMusicWebServicesReference/SetUpWebServices.html
Until I hit the part where I should use the requestUserToken(forDeveloperToken:completionHandler:) method from SKCloudServiceController in the StoreKit framework, since there is no StoreKit framework available for outside iOS/macOS/tvOS/etc.
How is this token generated? Is there any other way I can generate this Music User Token manually?
I know it is a (very) longshot, but maybe someone figured it out!

The new Apple MusicKit JS library allows you to create Music User Token's from your Developer Token as seen here outside of iOS. Once you've loaded the Library you can use the authorize method to allow a user to authenticate and generate a token.
document.addEventListener('musickitloaded', function() {
// MusicKit global is now defined
MusicKit.configure({
developerToken: 'DEVELOPER-TOKEN',
app: {
name: 'My Cool Web App',
build: '1978.4.1'
}
});
let music = MusicKit.getInstance();
music.authorize().then(musicUserToken => {
console.log(musicUserToken);
});
});

I have tried the approach within my iOS app.
You can follow this link generate music token
This is basically python script. You can easily create a music developer token from your mac.

Related

Stop the UnityAds Cookie permission seeking

I've just added UnityAds to my app and whilst testing production I noticed instead of an ad, it popped up a request to place cookies on the users device.
The SDK integration was fine but is an absolute deal breaker for me. Is there any way to turn on a setting where it doesn't do this? I turned off the seek personalised ads request in the iOS app, I don't want my users interrupted like this. I'd like to reject all on their behalf before they see it.
Yes, you can do that. Use my following code to pass the consent flag to Unity Ads SDK. And make the Unity Ads SDK not request cookie permissions for your users by setting this flag to false
MetaData gdprMetaData = new MetaData("gdpr");
gdprMetaData.Set("consent", "false");
Advertisement.SetMetaData(gdprMetaData);
// then Setup Unity ads
For people who is using Ironsource Mediation and have Unity Ads in waterfall but having the same problem.
IronSource.Agent.setConsent(false);
Warrning: but if you do that, all ads will not be personalized. The best way I recommend to you is:
On first opening, You need to show ATT (Application Tracking Transparency) popup. Then if the user clicks Allow then you set the consent to true if the user clicks Don't allow (Require apps not to track) then you set the consent false.
by the way:
If you don't want to show ATT in the first time. You need to set consent as false until ATT shows
*** Edit *** Ok found it in Swift, posting the code for posterity - Magoo
let meta = UADSMetaData()
meta.setRaw("gdpr.consent", value: false)
meta.commit()

How to use ''SpotifyiOS" framework and Authorize app without acutally playing a song

I am using 'SpotifyiOS' framework recommended by Spotify (https://github.com/spotify/ios-sdk) to access their APIs. To login/Authorise the App we must login to Spotify and it is invoked by following available methods:
where appRemote is an instance of SPTAppRemote
It plays a song even if I pass empty String as URI as shown below:
How can I authorise app without playing any song using 'SpotifyiOS' famework?
You can use the SPTSessionManager to authenticate without playing a song.
The flow is a bit more convoluted and better followed at the documentation link than copy/pasted here, but in short you configure the SPTSessionManager and provide it a delegate that on successful authentication provides a token to your SPTAppRemote which can then be used to control the application.

Does electron's registerHttpProtocol work in development?

I'm trying to register a custom protocol with electron. I want it to be a redirect location that a website can use to provide an api key (like myprotocol://example/payload=api-key). I have been using electron's registerHttpProtocol and also tried electron's interceptHttpProtocol.
But, when the website tries to redirect to my protocol my electron app doesn't do anything. The website goes to myprotocol://example/payload=api-key, and registers a "page doesn't exist error"--while nothing happens in my app.
This is in a development environment. I've seen some discussion about custom protocols that assume a production environment.
Can you register a custom protocol with electron in development?
Why am I not able to intercept the website's going to the protocol I've set out?
Here's my code:
main.js:
app.whenReady().then(() => {
protocol.registerHttpProtocol('examplep', (request, callback) => {
console.log("examplep", request);
callback('it-worked');
}, (error) => {
if (error) console.error('Failed to register protocol = ' + error)
})
protocol.interceptHttpProtocol("examplep", function (request, callback) { //I've tried both registerHttp... and interceptHttp... methods, so including both here; though I think in practice only one should be required
console.log('intercepted!' + request)
callback(request);
});
})
redirect url provided to website:
'http://examplep'
And I've whitelisted this url on the website itself.
I've also tried related methods registerStringProtocol, interceptStringProtocol, registerFileProtocol, and interceptFileProtocol, without success.
What am I missing?
Sounds like you need to support deep linking fora desktop app, which is done via a Custom URI Scheme and is registered with setAsDefaultProtocolClient.
When your Electron app starts up write this code to register the scheme, on the main side of your app:
const customScheme = 'x-mycompany-myapp';
app.setAsDefaultProtocolClient(customScheme);
The custom scheme can be tested from the command line like this, depending whether you are running macOS or Windows:
open x-mycompany-myapp:/some/location
start x-mycompany-myapp:/some/location
A web client will just invoke a URL as in this Javascript code of mine;
The notification will be received within the main side of your app and on Windows will attempt to create a new instance of the app, in which case you need to detect this condition, process the notification then cancel the new app instance.
On MacOS it will be received within the open-url event, so you register it like this:
app.on('open-url', this._onOpenUrl);
Once the main side of the Electron app has the notification, it needs to get the URL information and forward it to the renderer process. You can use ipcMain events for this.
Finally the code for receiving the notification in running instances and starting the app from a deep link are different.
EXAMPLE APP
Since the code is a little tricky, here is some example code that may be useful, to give you something to compare against. If it helps you can also run the app by following the instructions in the blog post:
Code
Blog Post
My use case is around receiving OAuth responses after signing in from the system browser. Hopefully you can borrow some ideas from it related to deep linking though.
INFO.PLIST
My understand is that in a development environment (on macOS) deep links work when the app is running, but if you stop the app and attempt a deep link it will not start the app.
You can only resolve this for a packaged app, which requires an info.plist. In my code sample the info.plist is generated from build protocol entries in the package.json file.
My code sample is packaged in a basic way by the Electron Packager, so when I run npm run pack, the app is built to a dist folder. I can then run the packaged version of the app and it gets registered with the system - as can be seen in the Default Apps tool. See screenshots in the blog post.
SECRETS
Secrets for a desktop app should be stored using operating system secure storage. There are screenshots of credential storage in the blog post.
On Electron, have a look at the keytar component - and this wrapper class of mine. I am storing tokens (strings) so you should be able to adapt the code for your API keys.

Firebase Dynamic Link on getInitialLink is null only on IOS and production link (React Native)

Is a React Native app and i use #react-native-firebase/dynamic-links version 7.1.0 (rnFirebase).
On android my dynamic link work correctly.
On ios with firebase test link work correctly (myUrl.page.link), but with a verified prefix url (myUrl) app are opened but my function dynamicLinks().getInitialLink() return null.
(I have add correctly url on associated domains in xcode)
I created the link with
const link = await dynamicLinks().buildShortLink(
{
link: encodeURI(
`myUrl/${list.generatedString}`
),
domainUriPrefix: 'myUrl',
analytics: {
campaign: 'banner'
},
navigation: {
forcedRedirectEnabled: false,
},
ios: {
bundleId: 'com.runeapp.gift-it',
// customScheme: 'giftit',
appStoreId: '1503678456'
},
android: {
packageName: 'com.runeapp.giftit'
}
},
'SHORT'
);
I wonder if the problem can be derived from the fact that the app has not yet been published on the app store.
Anyone have any idea?
thanks
dynamicLinks().getInitialLink() doesn't seem to work on iOS but here is a simple workaround I used in solving that:
When a user is on an iOS device, use the Linking package in react-native, then use the dynamicLinks().resolveLink() passing the URL returned from Linking. getInitialURL(), which would return the same response as dynamicLinks().getInitialLink(). Here is a snippet:
if (Platform.OS === 'ios') {
Linking.getInitialURL()
.then(res => {
dynamicLinks().resolveLink(res).then(response => {
console.log(response.url);
})
})
}
You could use the value from the Linking library directly but it is helpful to call the dynamic link resolveLink() in case you added extra parameters while building your link.
My issue was because I'm using API key restriction for the API key I use in my application. I extended the restriction to allow usage with the Firebase Dynamic Links API.
To allow your API key in question to be used with the new Firebase Dynamic Links API:
go to the Google Cloud Console
choose the relevant project (i.e. the project you use for your application)
open the menu and go to APIs & Services -> Credentials
click Edit API key for the API key in question
scroll down to API restrictions section
from the dropdown, choose Firebase Dynamic Links API
click Save
wait a couple of minutes for Google servers to update and retry...
When you open the app from the background you need to call onLink instead of getInitialLink

Web-apps: Can the iOS share sheet be triggered – and/or the shared URL customised – programatically?

Specifically, I would like to share granular page content via triggering the iOS share sheet with in-page buttons.
In my webapp page, I have a table of downloadable PDFs. I would like to be able to add a column called "Share" into the table, so that a button could be tapped to share the URL to that document, without having to open the document itself and share from there.
In order to do this, I assume I would need to customise this triggered share sheet to share a different URL to the one that is showing in mobile safari's address bar.
Is this possible using javascript, or alternative URLs in a meta tag maybe? I don't expect URL scheme to be a solution, as it is concerned with sending data to another application.
Addendum 6/2020 It is possible since iOS 12.4, it works great.
It will be supported in Safari iOS V12.2. The beta of V12.2 already has it.
There's a good article by Maximiliano Firtman on a number of new features that will be possible in the new version.
Not currently on ios but a new w3c spec is on the way called web share api. Currently only available in chrome for android behind a origin trail.
https://developers.google.com/web/updates/2016/10/navigator-share
Yes, via the Web Share API
per the w3 docs:
shareButton.addEventListener("click", async () => {
try {
await navigator.share({ title: "Example Page", url: "" });
console.log("Data was shared successfully");
} catch (err) {
console.error("Share failed:", err.message);
}
});
Great article by Joe Medley on web.dev: Integrate with the OS sharing UI with the Web Share API

Resources