In today extension, how could i get data from the main application? - ios

In my app's today extension, I want to get some text from the main app. I tried using NSUserDefault and Notification, nothing I could get. I don't want to copy the same lengthy code from the main app, so how could I do? Thanks!

Create Apps Groups Under Targets->Capabilities as shown in below screenshot,it should be unique
Now u can store info NSUserDefaults,but u have to use different methods for storing info with app groups name.Below i have given an example
NSUserDefaults *sharedDefault= [[NSUserDefaults alloc] initWithSuiteName:#"group.DigitalAnniversaries"]
[sharedDefault setValue:#"3" forKey:#"notification"]

If you enrolled Apple Developer program, the app group is a good way,or build a new target to share the data.

Related

how to access a sound file stored in another app in swift?

this question is a lot like Share data between two or more iPhone applications except:
I'm looking for a way to do this in an iOS 8+ (or 9+) application using swift
I want to be able to use the sound file contained in the first app so the easter egg I'm making is only available when the user has both apps installed
since this is part of an easter egg, i don't want to use any method that would cause anything extra to be displayed on screen such as a browser redirect or some kind of permission popup
(this basically rules out using the share sheet and custom url's to pass data as described in the post above)
I am using AVAudioPlayer and AVAudioSession in the first app to play the sound if that is at all helpful.
Use App Group
You can share actual NSData through the NSUserDefaults:
if let userDefaults = NSUserDefaults(suiteName: <group>) {
userDefaults.setObject(obj, forKey: key)
}
and retrieve from another app in the same group like so:
if let userDefaults = NSUserDefaults(suiteName: <group>) {
if let obj = userDefaults.objectForKey(key) {
// magic
}
}
It appears that the only limitation for passing data through the user defaults is the device storage capacity, and since NSUserDefaults accepts NSData as a storage format, it makes a prime candidate for sharing tidbits information.
If both apps are yours you can implement a custom url scheme in the second app, and then from the first app ask if it knows how to open an URL with that scheme. If the answer is yes, the app is installed. The function is called canOpenURL. It's an instance method of UIApplication.
I vaguely remember that in iOS 9 and later, Apple added a restriction that you have to register the URLs you are going to ask about in your info.plist, but I don't remember the details. That won't prevent this scheme from working, but it is an extra step you have to take.

iOS App - include rating-link - choose type of App ID

I'm close to submitting an app to the App Store and would like to include a rating-link in the first published version to present the user an easy way to rate the app or write a review.
So first I generated a new app via iTunes Connect without any further steps - just an empty hull. Inside the app there is an area named “App-Information” with a link at the bottom named “Show in App Store”. Of course this link is not active, because the app is not “Ready for Sale” at this time. But perhaps this link can be modified with GET-Parameters for example, to accomplish this task once the app is ready for sale.
Do you know how I can build an appropriate link for rating/writing reviews before the app is approved?
Then I don't know for sure whether to choose a wildcard App ID or not for a created app. Is the only criterion the need of using a service expecting an explicit App ID? For example, if I would like to store app related data inside iCloud then I would create and choose an explicit ID, and otherwise I also can use an already existing wildcard ID?
And can I first create an App with a wildcard App ID and choose an explicit App ID later when needed? I think I don’t understand the need or advantage of wildcard IDs in common, because a new App ID (explicit or not) is created within a minute with very little effort.
you can use this
itms-apps://itunes.apple.com/app/idYOUR_APP_ID
For versions lower than iOS 7 use the old one:
itmsapps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=YOUR_APP_ID
in code
define YOUR_APP_STORE_ID 545174222 //Change this one to your ID
static NSString *const iOS7AppStoreURLFormat = #"itms-apps://itunes.apple.com/app/id%d";
static NSString *const iOSAppStoreURLFormat = #"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%d"
[NSURL URLWithString:[NSString stringWithFormat:([[UIDevice currentDevice].systemVersion floatValue] >= 7.0f)? iOS7AppStoreURLFormat: iOSAppStoreURLFormat, YOUR_APP_STORE_ID]]; // Would contain the right link

iOS: Detect whether my SDK is installed on another apps on the device

I am developing a location based Q&A SDK for mobile devices.
When a question is asked about a specific location, the server side targets the most relevant user and sends the question to that user. If the user fails to answer, the question is sent to the second best user, and so on.
The problem is that my SDK might be installed on more than one application on the device, meaning that the user can get a question more than once.
Is there a way to detect whether my SDK is installed on more than one app? I thought that sending the UDID to the server might work, but iOS UDIDs differ between applications.
You can use UIPasteboard to share data between applications on the device.
The UIPasteboard class enables an app to share data within the app and with another app. To share data with any other app, you can use system-wide pasteboards; to share data with another app that has the same team ID as your app, you can use app-specific pasteboards.
In your SDK, do something like this:
#interface SDKDetector : NSObject
#end
#implementation SDKDetector
+ (void)load
{
int numberOfApps = (int)[self numberOfAppsInDeviceUsingSDK];
NSLog(#"Number of apps using sdk:%d", numberOfApps);
}
+ (NSInteger)numberOfAppsInDeviceUsingSDK
{
static NSString *pasteboardType = #"mySDKPasteboardUniqueKey";
NSData *value = [[UIPasteboard generalPasteboard] valueForPasteboardType:pasteboardType];
NSMutableArray *storedData = [[NSKeyedUnarchiver unarchiveObjectWithData:value] mutableCopy];
if (!storedData) {
storedData = [NSMutableArray new];
}
NSString *bundleId = [[NSBundle mainBundle] bundleIdentifier];
if (![storedData containsObject:bundleId]) {
[storedData addObject:[[NSBundle mainBundle] bundleIdentifier]];
}
value = [NSKeyedArchiver archivedDataWithRootObject:storedData];
[[UIPasteboard generalPasteboard] setData:value forPasteboardType:pasteboardType];
return [storedData count];
}
#end
If you only want to provide an SDK, it is not possible. Apple has added security steps to prevent that for user privacy. Keychain sharing will not work, because apps must share the same bundle seed ID (see here for more info).
If you want to provide an app along with your SDK, then you could do something like Facebook does, where app sends a "helo" message, Facebook asks user and finally Facebook sends "ehlo" message.
Your App -> "I would like to use the SDK; please give me token" -> SDK Controller App -> (Remember which apps have requested use) -> "OK, you can use the SDK; here is a token: #123" -> Your App
The SDK controller app can now send the server the list of apps.
I think you can group the apps on the same device by IP address as they will use the same address to connect to your server.
So the IP address will represent the device and the API key will represent the app that uses the SDK.
Can you try using
advertisingIdentifier
Not sure whether it serves your purpose. It is explained in here ASIdentifierManager class reference : Apple doc
I think its possible using keychain, you can have an unique keychain key in which you can save anything you want, and can be accessed by other apps if available. So for your SDK, lets say if there is one app, it will register some value in keychain with a unique key which is private to your SDK only if the key doesn't exist, and if it exist you get to know, since you can save any value in keychain, you can try multiple options and combinations which suits you.
You can use KeychainItemWrapper for the implementations.
Elaboration
Lets say we have an method.
[MySDK register];
Which can be used anywhere, say in AppDelegate. The register method will generate a token for the app, for the device, which we will save in the keychain using an unique key we have defined in the SDK, say in com.mysdk.key. And while saving in keychain the SDK can actually do a registration.
We consider the above method is implemented in multiple apps.
Now we have scenario.
User installs an App-A which uses the SDK, the register method will call and create a token and will save in keychain for the first time.
Now user installs another App-B which also uses the SDK, the same register method will call, but now it will check for the key com.mysdk.key in keychain, if exist it will just update the count for the token, which meant for the device.
Note
Keychain not meant to save only unique identifier, you can save other informations too.
Update
Check demo projects https://db.tt/7xpKrgMp
The wrapper I have used in the projects is same as SDK in your case which is same in both the projects.
Cheers.

Can an app know what its url in the app store will be? [duplicate]

This question already has answers here:
Get itunes link for app before submitting
(17 answers)
Closed 8 years ago.
I have a requirement for an app to share a link to itself on the app store via social sharing i.e. this sort of thing:
"I've been using this great app, you can get it at: "
Therefore the app needs to know what its app store url will be before it is submitted to the app store, is this possible?
You can use your app ID to construct the URL. You can get the ID from the iTunesConnect page for the app, then construct the URL thus:
#define APP_ID 653451876
NSString* url = [NSString stringWithFormat: #"http://itunes.apple.com/us/app/cap-that!/id%d",APP_ID];
See there https://stackoverflow.com/a/12764735/877032
You may be able to make an educated guess using the current format of the iTunes URLs which is:
https://itunes.apple.com/{country_code}/app/{app_name}/id{app_id}?mt=8
Once you create a "New App" in iTunes Connect, you should get your App id, so you could plug it into the URL.
Another alternative, if you have the ability to make a simple HTTP call from your app then you could simply bake the boilerplate portion of the URL into the code (e.g. https://itunes.apple.com/us/app/{app_name}/id{app_id}?mt=8), and then when your app launches, reach out to the URL where you've specified the proper id of your app. Save that in NSUserDefaults and construct the URL in code from that point on.
If you do not have a website or custom back-end, you could look into a service like Parse to help you out.
Good Luck!
If you are the developer of the app, in google play store you can know it, for example: https://play.google.com/store/apps/details?id=com.madfingergames.deadzone
https://play.google.com/store/apps/details?id=com.whawhawhat.referencejquery
You see that there is https://play.google.com/store/apps/details?id= and then the Package name
which is something like: com.mycompany.myfirstapp
In the iTunes store an app gets an id so it's not possible.

Android In-App Billing list of available products

Is it somehow possible to get a list of all available products from the Play Store?
What I want to do is to get all available items and then show them in a ListView. Whenever someone taps the ListView the right item is opened in Google Play Store.
Is that possible? And if yes, how?
As mentioned in this post, this is now possible using the Google Play Developer API (a.k.a. android-publisher):
https://developers.google.com/android-publisher/
In particular, the Inappproducts: list API:
List all the in-app products for an Android app, both subscriptions and managed in-app products.
Third-paty apis and services are not reliable. There is no reliable and convenient way for production yet. You have to store it on your server in encrypted json data file for example, without any php/java/something, just static file.
OR you can guess item skus in your code and check even non-existing items: myitem_00-myitem_99 for example.
You can try this Google Play Store Api, or you can also look into this Android Market API.
But both of these are unofficial.
This url will show you what to do:
http://developer.android.com/training/in-app-billing/list-iab-products.html#QueryDetails
You have to do below things.
establish the connection between your app and google play app.
Get the list of products which is register in your google console.
prapare arraylist that contains product's id name and put into Bundle
code to get purchase
ArrayList<String> skuList = new ArrayList<String> ();
skuList.add("premiumUpgrade");
skuList.add("gas");
Bundle querySkus = new Bundle();
querySkus.putStringArrayList(“ITEM_ID_LIST”, skuList);
finaly one methode is reday in google_play_app that we need to call
Bundle skuDetails = mService.getSkuDetails(3,
getPackageName(), "inapp", querySkus);
call the getSkuDetails method on the In-app Billing Version 3 API, and pass the method the In-app Billing API version (“3”), the package name of your calling app, the purchase type (“inapp”), and the Bundle is our response
extract the bundle and get the product names and display it in ativity.

Resources