Getting Device token in iphone6 - iphone

Now I am upgrading my app from ios7 to ios8.
The pushnotificatin works on iphone5 but not iphone6.
Please answer who have experienced in this field.
Thanks.

I've faced same problem and hope follow will help to you.
From ios sdk8, you can't use follow codes.
[application registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
Please try with this one.
UIUserNotificationSettings *settings =
[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound
categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];

Related

ITunes review URL and iOS 7 (ask user to rate our app) AppStore show a blank page

Does anybody knows if the technique used to ask the user to rate our app and open for him the App Store directly on the rating page is still working on iOS 7 ?
I used to open this url from my app :
itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=353372460&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software
But it looks like it's not working anymore (AppStore show a blank page). I have also tried this url wihout luck:
http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?pageNumber=0&sortOrdering=1&type=Purple+Software&mt=8&id=353372460
Starting with iOS7 the URL has changed and cannot direct for the review page but only to the app
itms-apps://itunes.apple.com/app/idAPP_ID
Where APP_ID need to be replaced with your Application ID. Based on the App ID from the question it would be the following
itms-apps://itunes.apple.com/app/id353372460
Notice the id in front of the number ... that string is is id353372460, not just 353372460
For anything pre iOS7 the 'old' URL needs to be used, only those could get you straight to the review page. You should also take note that these calls will only work on devices. Running them in the simulator will do nothing since the simulator does not have the App Store app installed.
Have a look at for instance Appirater for an implementation. https://github.com/arashpayan/appirater
Can't help you with phonegap specifics (never used it). But it basically comes down to checking the iOS version your user is running and then either use the old URL or then new iOS7 URL.
The following URL works perfectly on iOS 7.1:
http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=xxxxxxxx&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8
where the xxxxxxxx is your app ID.
UPDATE. Works on iOS 9.3.4 and iOS 10 GM (by Jeet)
This works on my end (Xcode 5 - iOS 7 - Device!):
itms-apps://itunes.apple.com/app/idYOUR_APP_ID
For versions lower than iOS 7 use the old one:
itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=YOUR_APP_ID
One-Line-of-Code Simple Alternative: ** Also See Simulator Comments Below **
http://itunes.apple.com/app/idAPP_ID
EDIT: Now that iOS 7.1 allows direct-link to the Reviews tab in the App Store, it's worth investing the extra lines of code to get there directly: see other answers for the rest.
here we are using http: instead of itms-apps:, let iOS do the rest of the work
I get the same results testing on iOS 6.1 & 7 devices (iPad/iPhone/iPod touch 4)
Specifically, this shortcut, for iOS 6 takes the user to the Details tab and not the Reviews tab.
The Purple+Software link gets the user all the way to the Reviews tab in iOS 6, which is obviously preferred if you know how to check the OS.
Important note: This will cause error in the simulator for iOS 5.1, 6.1 and 7.Cannot Open Page Safari can not open the page because the address is invalid (we know it is a valid URL outside the simulator, on any browser)
Just to be clear: On iOS 7: http:// provides the same experience as itms-apps: with no noticeable delay. * keep in mind that the simulator behavior noted above. This is not entire dissimilar from trying to access the camera via a simulator: the simulator is not the place to test it. *
It's not clear which versions of iOS this is supported by, but as part of iOS 10.3 there's a new query parameter that can be added to the URL: action=write-review. I have tested this on iOS 10.2 and 9.3.5 and it works. However, it does not work on iOS 7.1.2, so support was added between iOS 8.0 and 9.3.5. Further investigation is required!
Example: https://itunes.apple.com/app/id929726748?action=write-review&mt=8
This will open the "Write a Review" dialogue, rather than just showing the review tab.
Opening review page directly from app is possible in iOS7.
Please use the following url...
itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=YOUR_APP_ID
This will definitely works.. :)
+ (NSString *)getReviewUrlByAppId:(int)appId
{
NSString *templateReviewURL = #"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=APP_ID";
NSString *templateReviewURLiOS7 = #"itms-apps://itunes.apple.com/app/idAPP_ID";
NSString *templateReviewURLiOS8 = #"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=APP_ID&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software";
//ios7 before
NSString *reviewURL = [templateReviewURL stringByReplacingOccurrencesOfString:#"APP_ID" withString:[NSString stringWithFormat:#"%d", appId]];
// iOS 7 needs a different templateReviewURL #see https://github.com/arashpayan/appirater/issues/131
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 7.1)
{
reviewURL = [templateReviewURLiOS7 stringByReplacingOccurrencesOfString:#"APP_ID" withString:[NSString stringWithFormat:#"%d", appId]];
}
// iOS 8 needs a different templateReviewURL also #see https://github.com/arashpayan/appirater/issues/182
else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
reviewURL = [templateReviewURLiOS8 stringByReplacingOccurrencesOfString:#"APP_ID" withString:[NSString stringWithFormat:#"%d", appId]];
}
return reviewURL;
}
The review link has once again broken in iOS9. In doing some experimenting, I figured out that Apple reverted it back to how it was before iOS7. So you have to do:
itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=247423477&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software
Where 247423477 is your 9 digit app ID (the main difference is you have to append &onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software after the app ID).
All the answers above have now been deprecated (iOS 7, but may work) thus, I provide the new way Apple recommends to provide links to the Apps.
The link for your App is the one from iTunes (use Copy Link), this one is recommended for use in code:
Swift 3.0
let path = URL(string: "https://itunes.apple.com/us/app/calcfast/id876781417?mt=8")
UIApplication.shared.open(path!)
Or better -- treat the optional correctly and handle the possibility of not being able to reach the link:
if let path = URL(string: "https://itunes.apple.com/us/app/calcfast/id876781417?mt=8") {
UIApplication.shared.open(path) {
(didOpen:Bool) in
if !didOpen {
print("Error opening:\(path.absoluteString)")
}
}
}
Objective-C
#define APP_URL_STRING #"https://itunes.apple.com/us/app/calcfast/id876781417?mt=8"
then you can call APP_URL_STRING in your code:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: APP_URL_STRING] options:#{} completionHandler:nil];
Note, that this is the recommended way now by Apple, as the previous method of processing redirect links has been deprecated and are not supported.
The link for all your Apps, if you have more than one:
#define MYCOMPANY_URL_PATH #"http://appstore.com/mycompany"
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: MYCOMPANY_URL_PATH] options:#{} completionHandler:nil];
The App link above is recommended for use in code or links that are not seen directly by the user. If you want to provide link that may be seen and remembered by the user then use the following:
http://appstore.com/calcfast
Using this URL was the perfect solution for me. It takes the user directly to the Write a Review section. Credits to #Joseph Duffy.
For a sample code try this :
Swift 3, Xcode 8.2.1 :
let openAppStoreForRating = "itms-apps://itunes.apple.com/gb/app/id1136613532?action=write-review&mt=8"
if UIApplication.shared.canOpenURL(URL(string: openAppStoreForRating)!) {
UIApplication.shared.openURL(URL(string: openAppStoreForRating)!)
} else {
showAlert(title: "Cannot open AppStore",message: "Please select our app from the AppStore and write a review for us. Thanks!!")
}
Here showAlert is a custom function for an UIAlertController.
I have this to get the Product ID automatically and generate App Store Review and Product page links.
- (void) getAppStoreLinks {
productID = [[NSUserDefaults standardUserDefaults] objectForKey:#"productID"]; //NSNumber instance variable
appStoreReviewLink = [[NSUserDefaults standardUserDefaults] objectForKey:#"appStoreReviewLink"]; //NSString instance variable
appStoreLink = [[NSUserDefaults standardUserDefaults] objectForKey:#"appStoreLink"]; //NSString instance variable
if (!productID || !appStoreReviewLink || !appStoreLink) {
NSString *iTunesServiceURL = [NSString stringWithFormat:#"https://itunes.apple.com/lookup?bundleId=%#", [NSBundle mainBundle].bundleIdentifier];
NSURLSession *sharedSes = [NSURLSession sharedSession];
[[sharedSes dataTaskWithURL:[NSURL URLWithString:iTunesServiceURL]
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSInteger statusCode = ((NSHTTPURLResponse *)response).statusCode;
if (data && statusCode == 200) {
id json = [[NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingOptions)0 error:nil][#"results"] lastObject];
//productID should be NSNumber but integerValue also work with NSString
productID = json[#"trackId"];
if (productID) {
appStoreReviewLink = [NSString stringWithFormat:#"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=%d&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8",productID.integerValue];
appStoreLink = [NSString stringWithFormat:#"itms-apps://itunes.apple.com/app/id%d",productID.integerValue];
[[NSUserDefaults standardUserDefaults] setObject:productID forKey:#"productID"];
[[NSUserDefaults standardUserDefaults] setObject:appStoreReviewLink forKey:#"appStoreReviewLink"];
[[NSUserDefaults standardUserDefaults] setObject:appStoreLink forKey:#"appStoreLink"];
}
} else if (statusCode >= 400) {
NSLog(#"Error:%#",error.description);
}
}
] resume];
}
}
Open app's Review Page
- (IBAction) rateButton: (id)sender {
NSString *appStoreReviewLink = appStoreReviewLink;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appStoreReviewLink]];
}
Open app's App Store page
- (IBAction) openAppPageButton: (id)sender {
NSString *appStoreLink = appStoreLink;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: appStoreLink]];
}
It is said that this bug will be fixed on iOS7.1. Read here on the corona forum, and here on the iPhoneDevSDK.

What is the best way to get the current orientation for setting views

I want to detect the current orientation for setting the view,
which will be the better way for it from the below methods and how ?
[[UIDevice currentDevice]orientation]
[[UIApplication sharedApplication] statusBarOrientation]
You can use [[UIApplication sharedApplication] statusBarOrientation] to detect device orientation.
This method returns orientation value for all cases but if you use
[[UIDevice currentDevice]orientation]
sometimes you get unknown orientation.
I hope that works for you.
you can use below code:
if (UIInterfaceOrientationIsLandscape([[UIDevice currentDevice] orientation]))
{
NSLog(#"-Landscape");
}
else
{
NSLog(#"-Portrait");
}

Blocking touches in cocos2d

Is there a way to totally block touches in cocos2d (assume, file or something is loading and I don't want user to be able press anything) ?
Manually you need to remove touches for menu and layer.
//Cocos2d 2.0
menu.touchEnabled = NO;
layer.touchEnabled = NO;
//Cocos2d 1.0
menu.isTouchEnabled = NO;
ignore all interactions:
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
to unignore use:
[[UIApplication sharedApplication] endIgnoringInteractionEvents];

Build succeeds but black screen

The build process is fine but then i get a black screen. I tried putting a breakpoint in the app delegate but it doesn't seem to run.
What could it be?
This is my didFinishLaunchingWithOptions method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Init Airship launch options
NSMutableDictionary *takeOffOptions = [[[NSMutableDictionary alloc] init] autorelease];
[takeOffOptions setValue:launchOptions forKey:UAirshipTakeOffOptionsLaunchOptionsKey];
// Create Airship singleton that's used to talk to Urban Airship servers.
// Please populate AirshipConfig.plist with your info from http://go.urbanairship.com
[UAirship takeOff:takeOffOptions];
// Register for notifications
[[UAPush shared] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
usersData = [PlayersData sharedInstance];
//[usersData cleanUserDefauts]; // --- use to clean user defaults
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.loadingPageVC = [[LoadingPage alloc] initWithNibName:#"LoadingPage" bundle:nil];
self.window.rootViewController = self.loadingPageVC;
[self.window makeKeyAndVisible];
ConnectionManager *connectionManager = [ConnectionManager sharedInstance];
NSLog(#"Connection statement: %#",[connectionManager checkConnection]);
if ([[connectionManager checkConnection] isEqualToString:#"connected with wifi"] || [[connectionManager checkConnection] isEqualToString:#"connected with wwan"] ) {
[connectionManager getLocation];
}
return YES;
}
Sometimes(Very Rarely) XCode can behave different.If something is really weird i would do the following things.
Do a clean build
Remove your app in the Simulator and Build Again
Restart Simulator and Build Again
Close XCode and Reopen it
Worst case is to restart the System
No need to resart anything. Just follow a step given below & you will achieve what you want.
1. Go to /Users/<MAC_NAME>/Library/Application Support/iPhone Simulator/<SIMULATOR_VERSION>, delete all & run app
Enjoy Programming!
I think you may have changed your xib name from ViewController to LoadingPage.
If so, then you must have to delegate it from your .xib. From the top-right corner. Like,
I have just given my opinion that this may be your solution. If you have succeeded with another one, let me know.....:)
Ok! This is solved.
Apparently someone I work with changed one simple word and that messed everything up…
He made the appDelegate inherit from UIApplication instead from UIResponder.
Now it works.

How to open iPhone's default browser?

I placed a Facebook button in my iPhone app. How to open the iPhone's default browser when clicking on that button and loads the Facebook login page?
iOS 10 has introduced new method to open a URL, see below:
Swift 3:
let url = URL(string:"http://www.booleanbites.com")!
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
// Fallback on earlier versions
UIApplication.shared.openURL(url)
}
Objective C:
NSURL *url = [NSURL URLWithString:#"http://www.booleanbites.com"];
if ([[UIApplication sharedApplication] respondsToSelector:#selector(openURL:options:completionHandler:)]) {
[[UIApplication sharedApplication] openURL:url options:#{} completionHandler:NULL];
}else{
// Fallback on earlier versions
[[UIApplication sharedApplication] openURL:url];
}
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.facebook.com"]];
When you open iPhone's default browser, your application gets to background - possibly terminated by iOS. Is that really what you want? User has no way to get back to your app.
Couple options to consider:
Integrate Facebook iOS library into your application. Lots of coding, since you need to write some UI code to support the integration. On the other hand it's your application and you have some control over what is going on and how to react to user actions
https://github.com/facebook/facebook-ios-sdk
Embed browser inside your application and "open the browser" within your app. Yet again you have some control over what's going on and what to do about it
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebView_Class/
The point is: it's YOUR application. Why would you force user to shutdown your app and start using something else without any way to get back?
Well, you know all the details and based on those you want the default browser. That's ok.
In Swift
UIApplication.sharedApplication().openURL(NSURL(string:"http://www.facebook.com")!)
In objective C
[[UIApplication sharedApplication] openURL:[NSURL
URLWithString:#"http://www.facebook.com"]];
Swift: iOS
var url:NSURL? = NSURL(string:webLink!)
UIApplication.sharedApplication().openURL(url!)
Swift 3:
let url = URL(string: "http://www.example.com")!
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
If you want to add a completionHandler:
let url = URL(string: "http://www.example.com")!
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: { (success) in
print("success!") // do what you want
})
}
OpenUrl is depricated, Use the following code.
NSURL *url = [NSURL URLWithString:#"https://google.com"];
[[UIApplication sharedApplication] openURL:url options:#{} completionHandler:nil];