I added Google Analytics SDK to my project, following the provided instructions on the guide by Google. However, when I try to track some events, this is the debug output:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[…]
// Google Analytics
[GAI sharedInstance].trackUncaughtExceptions = YES;
[GAI sharedInstance].dispatchInterval = 20;
[[[GAI sharedInstance] logger] setLogLevel:(PADEV ? kGAILogLevelVerbose : kGAILogLevelError)];
[[GAI sharedInstance] trackerWithTrackingId:#"UA-XXXXXXXX-Y"]; // This is obviously replaced with my tracking ID
return YES;
}
and
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:#"article"
action:#"read"
label:#""
value:self.post[#"id"]] build]];
Log:
2014-11-12 01:02:25.144 PonzApp[5236:112706] INFO: GoogleAnalytics 3.10 -[GAIBatchingDispatcher didSendHits:response:data:error:] (GAIBatchingDispatcher.m:208): Hit(s) dispatched: HTTP status -1
2014-11-12 01:02:25.146 PonzApp[5236:112781] INFO: GoogleAnalytics 3.10 -[GAIBatchingDispatcher deleteHits:] (GAIBatchingDispatcher.m:509): hit(s) Successfully deleted
2014-11-12 01:02:25.147 PonzApp[5236:112781] INFO: GoogleAnalytics 3.10 -[GAIBatchingDispatcher didSendHits:] (GAIBatchingDispatcher.m:219): 1 hit(s) sent
It says that the hits are sent but the HTTP status is weirdly -1 and if I check on the dashboard, section “real-time”, nothing appears.
What could be wrong?
From Google Analytics tracking setup
Once you've correctly installed the tracking code snippet, you should
allow up to 24 hours for data to appear in your account. If it has
been more than 24 hours and you're still not seeing any data, take a
look at the list of possible reasons below:
Once the system has detected your tracker you will start seeing data in the real-time reports. Some of the data may also appear in the standard reports but it is not reliable as it takes 24 hours for data to finish processing.
All and all your code looks fine you just need to wait. The above is the same even though it is a application tracking. I suspect it takes time for Google to set up the new account on there side.
For me the problem was that I was testing it in simulator... :|
If you are using simulator to test it, make sure to press command + shift + H on the simulator to back to home since the data will be sent when it's on background.
Related
I've implemented apple watch app to run independently, So all web services made in Watch itself. It seems to be working fine in watch OS 2 But When request made in watch OS 3 getting Status code as 401.
The flow would be :
1. Making login follwed by get detials web services request in iPhone and share login details to watch app to initiate same request in watch os.
Watch OS 1 & 2.x - No issues
Watch OS 3 - Getting sucess for Login request and 401 error for get details service call.
Please Note : There is no code change made for Watch OS 2 & 3 , also there is no session mangement handled in back end.
Any body facing same issues or any solution for this ? .
Finally got solution, after adding the below lines it worked for me.
if let httpResponse = response as? HTTPURLResponse, let fields = httpResponse.allHeaderFields as? [String : String] {
let cookies = HTTPCookie.cookies(withResponseHeaderFields: fields, for: response!.url!)
HTTPCookieStorage.shared.setCookies(cookies, for: response!.url!, mainDocumentURL: nil)
}
I presume Watch OS2 by default manages cookies but Watch OS3 not. So we manually have to store cookies it seems.
I am calling scanForPeripheralsWithServices from didFinishLaunchingWithOptions callback of AppDelegate. The code looks like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
NSLog(#"didFinishLaunchingWithOptions");
// Override point for customization after application launch.
cm = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
[cm scanForPeripheralsWithServices:nil
options:nil];
}
- (void) centralManager:(CBCentralManager*)central didDiscoverPeripheral:(CBPeripheral*)peripheral advertisementData:(NSDictionary*)advertisementData RSSI:(NSNumber*)RSSI{
NSLog(#"Did discover peripheral %#", peripheral.name);
[cm stopScan];
}
Before upgrading to iOS 8 everything was working well, however after the upgrade (exactly the same code, no single line was changed) I am not getting any error, but also didDiscoverPeripheral is not being called.
I appears that the major change which has occurred with Core Bluetooth in iOS 8 is that the BLE stack isn't powered on until you try to connect (or possible issue some other command).
CBCentralManager *cbCentralManager;
[cbCentralManager scanForPeripheralsWithServices:...];
This call used to issue a warning visible in the Xcode debug log saying that the central manager needed to be powered-up before it could be used. However, this warning was always a catch-22 — the only way to power-on the central manager was to send it a message, and the only way for it to process a message was for it to be powered-on.
Apple seems to have resolved this problem by handling power-on a bit differently. Now, after issuing the above command the central manager tells its delegate that its state changed via centralManagerDidUpdateState:.
We resolved the problem you describe by responding to centralManagerDidUpdateState: by re-issuing the scanForPeripherals... message.
Briefly
I want to code a status bar app that will send commands through an https connection using PHP / cURL.
What I Have and Know
Mac OS X running Mountain Lion (with X-code)
Extra-beginner coding skills in Objective-C
An API's documentation with instructions on what text to send via PHP/cURL
YouTube tutorial: Xcode 4.1 Tutorial - Create a menu bar application (NSStatusItem / StatusBar app) + DOWNLOAD
Interest in starting simple, but building to more complexity
What I Don't Have or Know
How to code the POST/GET commands into the app so that they fire upon click.
The Specific Use Case
I want to create a very basic status bar app that does two things related to the Cloudflare CDN / proxy app. CloudFlare's API allows for commands to a user's account sent over https with PHP / CURL commands.
I'd like to build a status bar app with hard wired commands executable via click. The click would perform either a mode change (like entering development mode) for a website, or a cache purge for the website. These are tasks that can be performed in the front end of the CloudFlare website and the API docs give some very clear direction on how to structure the GET/POST requests (so no help is needed on that end of things).
Gratitudocity
I'm super grateful in advance to anyone who can provide me with some pointers, resources, or additional things to think about.
Well I am not going to answer the part about setting up the status bar and adding status bar items and connecting them to actions in your controller, but I will point you in the direction of NSURLConnection and NSMutableURLRequest, rather than curl.
Example:
NSMutableURLRequest * req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:#"www.example.com"]];
[req setAllHTTPHeaderFields:#{#"header1":#"value1"}];
[req setHTTPBody:[NSData data]];//not really doing anything
[req setHTTPMethod:#"GET"];
NSURLResponse * respMeta = nil; //will contain returned headers, etc
NSError * err = nil; // on failure will contain error object
NSData * response = [NSURLConnection sendSynchronousRequest:req returningResponse:&respMeta error:&err];
I encountered a facebook login problem. I installed FB SDK 3.0 and sample projects seemly run well --- not quite sure though. When I create a button in my own project and try to log in to Facebook, I always get FBSessionStateClosedLoginFailed from sessionStateChanged method, although I apparently get the page "You have already authorized this app. Press Okay to continue". I also tried log out through Simulator Safari facebook page, and re-launched my project and I got new username/password page and I then logged in, but I still get FBSessionStateClosedLoginFailed!
A few more observations.
1, I got FBSessionStateClosedLoginFailed thru NSLog, the log comes up right after I clicked Okay button on the Facebook page "You have already authorized this app.
2, I tried clean xcode project cache, but no help.
Kind of frustrated. I wonder if any of you can help on this problem. Appreciated!
-Tony
Addition:
I did a bit more research, and I found what I have is probably a typical problem, as Facebook highlight here ("Pro-tip 3: Complete all iOS App Settings" section in page http://developers.facebook.com/docs/howtos/login-with-facebook-using-ios-sdk/). The image with a big red cross over iPhone is exactly what I have. From xcode project, I click my login button, and I'm directed to this page, and every time I have to click "Okay" on this page (let me call it Okay_page) to go back to my app in Simulator, however with login status as FBSessionStateClosedLoginFailed. I checked bundle ID, I have it correct. I don't have a 'YOUR_IPHONE_APP_STORE_ID' yet, which I believe I need pay Apple to get and I will do it later but not while I'm still working on it.
Now get a couple of questions:
1, Do I have to have YOUR_IPHONE_APP_STORE_ID to skip this Okay_page?
2, Does this (not automatically re-directed back to my app from this Okay_page) have anything to do with that I always get a login status of FBSessionStateClosedLoginFailed when I manually click Okay in this Okay_page and return to my app in Simulator? In another word, is (that I have to manually click Okay to get back to my app in Simulator) (the reason I got a status of FBSessionStateClosedLoginFailed)?
Did you have set this function in AppDelegate?
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [FBSession.activeSession handleOpenURL:url];
}
I had the same issue:
We created the facebook app (developer.facebook.com) setting our
bundle id (ex. com.MyCompany.MyApp)
Off course, created our iOS app with the same bundle id
After delivered our app to the client, he changed the bundle id
without notify us.
Obviously he started to get FBSessionStateClosedLoginFailed errors!
So, you probably have different bundle id's between your iOS project and your Facebook App.
I had this error and couldn't resolve it for quite some time. It turns out that if you are using the native iOS Facebook account in settings and choose "no" for allow Facebook for this app, the app is blocked by the OS. You will always get the FBSessionStateClosedLoginFailed error and there is nothing you can do inside the code to fix this (99% sure). The best you can do is alert the user to check out the settings.
i am typing wrong line in given below method. self.session was nil
return [self.session handleOpenURL:url];
it should be
return [[FBSession activeSession] handleOpenURL:url];
Use Following Method.
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
return [[FBSession activeSession] handleOpenURL:url];
// return [self.session handleOpenURL:url];
}
I fixed this problem after I reset the simulator. iOS Simulator - Reset Content and Settings..., hope to help.
I had this issue because I was calling [FBSession.activeSession close] in my applicationDidEnterBackground: app delegate callback. This closed the session so that when the redirect brought the app back up to open the session, it failed because it had been put into the closed state.
Make sure that you're not closing the session anywhere before you get to the Okay page.
go to Facebook.com. Open your application on the left panel -> Status & Review -> there is a toggle with text "Do you want to make this app and all its live features available to the general public?". Turn it on
well. I followed FBLoginCustomUISample somewhere on github.com and it was a working example of facebook login implementation from facebook itself. You can also read my workaround while creating facebook login feature in a iOS app. Here is a link form me:
Native iOS Facebook SSO won't return to app
Hmmm……
A question about UILocalNotification and the notificaton's alertLaunchImage.
My app uses UILocalNotifiaction(s) to get users' attention. As usual, an alert is presented with "Action" and "Close" buttons. When the user taps Action, the image specified by alertLaunchImage is presented. The alertLaunchImage is a screenshot of of one of the views of the app which is shown after the data is initialized when launched normally.
Here are the 3 cases when the notification is delivered:
App is running in foreground - no alert, no launchImage is shown as designed. No problems.
If my app is running in background when the notification is delivered, the launchImage works like a charm. No problems. The launchImage with no app-related data is shown and then the app fills up the data. This part works seamlessly.
However, if the app is not running when the notification is delivered, the sequence is confusing - or I missed something. The app gets launched and shows the alertLaunchImage instead of the Default image. Then is goes thru several other screens (as part of initialization and data processing) before the actual screen (live version of alertLaunchImage) is shown.
This can get very confusing to the user. My question comes in here. How can this be avoided?
R/-
Sam.!
you can try cleaning up the alert view settings in applicationWillTerminate:
According to the UIApplicationDelegate reference applicationWillTerminate::
"This method lets your application know
that it is about to be terminated and
purged from memory entirely. You
should use this method to perform any
final clean-up tasks for your
application, such as freeing shared
resources, saving user data,
invalidating timers, and storing
enough application state to
reconstitute your application’s
interface when it is relaunched"
HTH,
Oded
If your app is launched by a local notification, you will receive that notification in the options passed to -application:didFinishLaunchingWithOptions:. Based on that, you can write code that navigates to the correct screen without animations.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UILocalNotification *localNotification = [launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification != nil) {
// startup by local notification
} else {
// normal startup
}
}