Apparently, my use of Twitter oAuth (token request) doesn't work in iOS 5... how can I keep this code for anything below iOS 5 and use the new Twitter Framework for iOS 5+?
Is it possible to detect iOS versions?
Thanks!
You (almost) never want to query iOS (or even framework) versions. That (usually) means you're solving the wrong problem.
In this case, you really want to know "can I use Twitter.framework?"
Thanks to the magic of weak linking, you can try something like:
if ([TWTweetComposeViewController canSendTweet]) {
// Do something
}
else {
// Use your original code
}
You can also check for lower level framework components, e.g.:
if ([TWRequest class]) {
// Do something
}
else {
// Use your original code
}
(Obviously you will need to link against Twitter.framework and include the requisite headers.)
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
//tweet
}
First and foremost, the other answers are correct-- you should avoid using iOS version number to check if features exist.
HOWEVER: In case you do indeed have a good reason to check iOS version, my all-time favorite answer for checking iOS version number is in this StackOverflow answer. So elegant.
Detect if the Twitter class is in the installed os :
if (NSClassFromString(#"TWTweetComposeViewController")) {
//use Twitter Framework
}
Do not forget to make the Twitter Framework optional in the list of Frameworks.
Related
I need to get the Versions of all the installed applications programmatically for non-jailbroken iOS devices.
Is it Possible to achieve this?
That's possible, please try the below code.
Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
NSObject* workspace = [LSApplicationWorkspace_class performSelector:#selector(defaultWorkspace)];
for (LSApplicationProxy *apps in [workspace performSelector:#selector(allApplications)])
{
NSString *localizedName = apps.localizedName;
if([apps.applicationType isEqualToString:#"User"])
{
NSLog(#"\nlocalizedName: %#",localizedName);
NSLog(#"minimumSystemVersion: %#",apps.minimumSystemVersion);
NSLog(#"fileSharingEnabled: %d",apps.fileSharingEnabled);
NSLog(#"sdkVersion: %#",apps.sdkVersion);
NSLog(#"teamID: %#",apps.teamID);
}
}
For this you need to place 4 classes in your app:
LSApplicationWorkspace, LSResourceProxy, LSBundleProxy, LSApplicationProxy.
In iOS8 and before, we can use canOpenUrl to get installed applications which registered schemes. In iOS9, you must add a "white list" into your info.plist file. Only the application in the "white list" can be checked. And the limit count of the "white list" is 50. So you'd better jailbreak your device.
See more information: How to check particular app is already installed on iphone device or not?
Another one: http://useyourloaf.com/blog/querying-url-schemes-with-canopenurl.html
Isssue 1:
I'm following this estimote tutorial to create my own Estimote app. However this error appeared:
Unknown type name 'ESTBeaconRegion'; did you mean 'CLBeaconRegion'?
How to solve it?
I've included the header and also the delegate
#import <EstimoteSDK/EstimoteSDK.h>
#interface AppDelegate () <UIApplicationDelegate,CLLocationManagerDelegate,ESTBeaconManagerDelegate>
This is my podFile
# Uncomment this line to define a global platform for your project
platform :ios, '7.0'
target 'Tabster' do
pod 'EstimoteSDK', '3.1.0'
end
Issue 2:
Why is the framework highlighted in red?
Update: (trying the Example app suggested by Juan Gonzalez)
If you want to use an "old app" with the new estimote SDK 3.0, i suggest you to go read the migration guide at this adress :
https://github.com/Estimote/iOS-SDK/blob/master/SDK_3_0_MIGRATION_GUIDE.md
ESTBeaconManager
ESTBeaconManager class remains, but with narrowed functionality. In the current form it is responsible for ranging and monitoring iBeacon devices as well as advertising as iBeacon. It mainly covers CoreLocation functionality but with useful helpers including preventUnknownUpdateCount, avoidUnknownStateBeacons and returnAllRangedBeaconsAtOnce (Already available in previous versions of Estimote SDK).
Delegate methods works with CLBeacon objects (instead of ESTBeacon) and CLBeaconRegion (instead of ESTBeaconRegion). Let's use ranging delegate as example:
SDK 2.4 syntax:
- (void)beaconManager:(ESTBeaconManager *)manager
didRangeBeacons:(NSArray *)beacons
inRegion:(ESTBeaconRegion *)region
{
if (beacons.count > 0)
{
ESTBeacon *firstBeacon = [beacons objectAtIndex:0];
}
}
SDK 3.0 syntax:
- (void)beaconManager:(id)manager
didRangeBeacons:(NSArray *)beacons
inRegion:(CLBeaconRegion *)region
{
if (beacons.count > 0)
{
CLBeacon *firstBeacon = [beacons objectAtIndex:0];
}
}
I hope that will help you.
I have had the same issue using Estimote SDK library. For an unknown reason, if you try to include SDK library in a new Xcode project it doesn't seems to load it. Even if you use CoreLocation and CoreBluetooth headers.
I suggest you to use the sample code in order to have a project including libaries and then start to modify it.
Download code from here and don't try to export it from pod file instead of that you can directly use Example xcode project exported from iOS-SDK zip file you downloaded. Try it once if you are getting same problem or not.
from heypiotr, "In SDK 3.0 we switched from ESTBeaconRegion to CLBeaconRegion, this tutorial you're doing wasn't yet updated to reflect that. It's easy though: just change all your ESTBeaconRegion occurrences to CLBeaconRegion. And while you're at it, we also changed ESTBeacon to CLBeacon, so you may want to replace these as well." That explains everything. Thx guys!
Can XCode check for the code compatibility against a specific OS X version? or an external tool?
I have a project that's using a function exists at 10.9 and newer, though I set xcode deployment target to 10.7, it builds without errors but when trying to run the application on 10.8, it doesn't work!!
how can I get functions minimum OS version required?
Xcode does not provide a tool to check whether a method is available for the deployment target. But if you know that some method is only available from a specific version you can check whether the method is available:
if ([self respondsToSelector:#selector(newMethodNotAlwaysAvailable:withParameters:)]) {
[self newMethodNotAlwaysAvailable:#"1" withParameters:YES];
}
else {
// Call some other method to just don't do anything.
}
You can also do ut for classes:
if ([SomeNewClass Class] ) {
// Class is available and you can use it
}
The documentation says it's available in MacOS 1.08.
So what's the story? What about for iOS5?
It's a very important selector because self[5] will actually turn into [self objectAtIndexedSubscript:5] unless I am missing something.
Doesn't work in NSOrderedSet but works in NSArray.
What am I missing?
While objectAtIndexedSubscript: is not available previous to iOS 6, NSArray and NSDictionarysubscripting is available. That means that you can use syntax like this:
myArray[2] = #"thingie";
myDictionary[#"roger"] = #"barry";
And it will deploy back to iOS 4.
However NSOrderedSet subscripting will not work on iOS 5 and previous. For that, you will need to provide a category that redirects objectAtIndexedSubscript: calls to objectAtIndex:.
Addendum: Apple's docs for NSMutableOrderedSet are also incorrect. It states that index subscripting does an insert, when in reality is does a replace (as one would expect).
No, only since iOS 6 unfortunately.
Apple has separate documentations for the OS X and the iOS APIs. You have to check the right one: objectAtIndexedSubscript:.
Availability
Available in iOS 6.0 and later.
If you need your code to run on iOS 5, you'll need to replace
myOrderedSetOfHilariousAcronyms[2] = #"ROFL";
with
[myOrderedSetOfHilariousAcronyms setObject:#"ROFL" atIndex:2];
I look at the NSOrderedSet.h file and I saw this:
- (id)objectAtIndexedSubscript:(NSUInteger)idx NS_AVAILABLE(10_8, 6_0);
So it doesn't work for IOS5.
I'm new to IOS development, sometimes I use a function but ignore its Doc.
So, I may use some functions are only supported on IOS 4 or even IOS 5, but I want to support IOS 3+.
Does it has any way to check if my app support IOS 3+?
I don't want to check line by line, thx.
And BTW, anonymous function like void (^ funcName)(NSString *) is objective-c feature, right? So it is supported on all IOS version, right?
Change your 'Deployment Target' to 3.x to see if any methods you're using aren't supported on that version.
That however is not a substitute for testing on 3.x; so either find a 3.x device or drop support for that version. Also, blocks (the 'anonymous function' you describe) are only available on iOS 4 and above.
If you want to write different sets of code for different version targets, you can use preprocessor directives:
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 50000
... 5.x code here ...
#elif __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
... 4.x code here ...
#else
... 3.x code here ...
#endif
Try running your app on a device running 3.x
by anonymous functions do you mean blocks like:
[self performSomeBlock:^(NSString *smth) {
NSLog(#"%#", smth);
}];
or do you mean just c like definitions (its late so i forgot the legit name)
void doSomething(void *(*func)(NSString *)) {
...
}