phonegap push notification showing errors in Xcode - ios

So I'm incorporating the phonegap plugin for push notifications into my phonegap app but was receiving an error in my consol saying that #import <Cordova/JSONKit.h> was wrong and the file couldn't be found. So going off this post here I was able to resolve the error but now its coming up with two addition warnings.
NSString* uuid = [[UIDevice currentDevice] uniqueIdentifier]; uniqueIdentifier in depreciated
and
NSString *jsStatement = [NSString stringWithFormat:#"window.plugins.pushNotification.notificationCallback(%#);", [userInfo cdvjk_JSONString]]; instance method -cdvjk JSONString not found
Has anyone come across this before? I'm using phonegap 2.4.0

The first error is due to UUIDs being deprecated, unless you fix that warning your app will never be accepted into the app store. The fix is easy, replace [[UIDevice ...] ...] with:
NSString *uuid = [[ASIdentifierManager sharedManager] advertisingIdentifier]
For the second issue, change cdvjk_JSONString to JSONString, this will be resolved in the next release of Cordova / PhoneGap.

Related

How to check if app is running from xcode

I'm using a test library to see me crash report, and I need to know if the app is running from Xcode, I know that exist the DEGUB parameter, but it does not work because if install app from xcode and open it, DEGUB parameter will be in YES.
Thanks.
Not exactly what you want, but you can check if the cable is plugged in, so if it's just for testing the solution should be enough.
[[UIDevice currentDevice] batteryLevel]
or
[[UIDevice currentDevice] UIDeviceBatteryState]

Get UDID in iOS 8 +

I need to get the UDID of my iPhone to use in my iOS app.
Some info about my app:
My app is not for the public and will never make it to the store, so I can use any 3rd party libraries. It will only be used by some employees at work.
My device will always be plugged into a Mac, while my app is running.
The way I see it, there are only 2 ways this can be accomplished.
Use a third party library to get the UDID inside of my iOS app.
Since the iPhone will always be plugged into a Mac while my app is running, how about getting the UDID via the Mac and transferring it in some way to my app in the iPhone.
Any ideas would be appreciated. Thanks.
Edit: Question is, do you know any 3rd party libraries or a better way to get my app to automatically get the iPhone's UDID while running?
Edit 2: I know this can be done using only my phone because of this web app: http://get.udid.io/
How does this work?
If you're trying to read the UDID to automate something on the Mac, then you can use something like system_profiler SPUSBDataType to get the UDID, for my phone the entry:
Product ID: 0x12a8
Vendor ID: 0x05ac (Apple Inc.)
Version: 7.01
Serial Number: 7bed*********************************33
Speed: Up to 480 Mb/sec
Manufacturer: Apple Inc.
Location ID: 0x1d110000 / 6
Current Available (mA): 500
Current Required (mA): 500
Extra Operating Current (mA): 1600
The line Serial Number is the UDID (I've starred it out as I'm stupidly paranoid).
Note, that without the UDID you could never have got the app onto the phone in the first place.
You could run a small daemon process on the mac, reading this information and creating a bonjour service that provides the information to requestors - it's a SMOP.
It's very simple. Go to Xcode Window and select Devices or you can find it in Organizer.
http://www.raywenderlich.com/2915/ios-code-signing-under-the-hood/organizerudid
From a quick look online, it looks like you can use a private framework called libMobileGestalt.dylib.
After linking the library and importing the header, you should be able to do something like this (reference):
CFStringRef value = MGCopyAnswer(kMGUniqueDeviceID);
NSLog(#"Value: %#", value);
CFRelease(value);
On my Mac, I can find that particular dylib here:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/libMobileGestalt.dylib
Use this code in ios 9
NSUUID *tempUUID = [[UIDevice currentDevice] identifierForVendor];
NSString *stringForUDID = [tempUUID UUIDString];
NSCharacterSet *notAllowedChars = [[NSCharacterSet characterSetWithCharactersInString:#"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"] invertedSet];
NSString *resultString = [[stringForUDID componentsSeparatedByCharactersInSet:notAllowedChars] componentsJoinedByString:#""];
NSLog(#"Final string %#", resultString);
Here is the github project which seems correct for your requirement
Here is the code that works
#import <Foundation/Foundation.h>
#import <CoreFoundation/CoreFoundation.h>
#import <liblockdown.h>
#include <stdio.h>
...
LockdownConnectionRef connection = lockdown_connect();
CFStringRef udid = (CFStringRef)lockdown_copy_value(connection, NULL, kLockdownUniqueDeviceIDKey);
CFShow(udid);
lockdown_disconnect(connection);
Use this: [[[UIDevice currentDevice] identifierForVendor] UUIDString];

Generating unique id for iphone

Hi I am developing small iphone application in which I want to generate unique id for my device. I am using following thing :
-(NSString*)uniqueIDForDevice
{
NSString* uniqueIdentifier = nil;
if( [UIDevice instancesRespondToSelector:#selector(identifierForVendor)] ) { // >=iOS 7
uniqueIdentifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
} else { //<=iOS6, Use UDID of Device
CFUUIDRef uuid = CFUUIDCreate(NULL);
//uniqueIdentifier = ( NSString*)CFUUIDCreateString(NULL, uuid);- for non- ARC
uniqueIdentifier = ( NSString*)CFBridgingRelease(CFUUIDCreateString(NULL, uuid));// for ARC
CFRelease(uuid);
}
return uniqueIdentifier;
}
So i tested this code locally. Mean Every time when I uninstall and install it again it will create same unique code for me. But when I push it to app store that time for every installation on same device it is generating different code. I want to generate same code for each installation on same device. Is there any method to do this. Need some help.
I want to generate a unique identifier for device which will be same for my device even I install and uninstall application many times. I am using OIS 7.0 version.
Thank you.
The identifierForVendor changes only after a system restore, you can check some of my test here:iOS 7 access UUID value in an enterprise application (not for AppStore).
In case of iOS version lower than ios6 you can save the id in the keychain, it will persist even after app uninstall

Cordova how to remove "Push notification" on iOS

I submitted my application using Apache Cordova to Apple Store and I got a warning from apple that "Missing Push Notification Entitlement".
But it seems that I've never used "Push Notification" in my application. How can I remove it from my application? Is it default in Apache Cordova?
HOW TO DO THIS FOR CORDOVA APPS 'PROPERLY':
I also had this problem. The solution proposed by #michaelb worked but I was frustrated enough seeing that the whole thing was wrapped in conditional compilation (ie #ifndef DISABLE_PUSH_NOTIFICATIONS) that I decided to learn how to add a 'Preprocessor Macro', which basically tells XCode to compile you app with this bit of code left out.
This is how the you can define the DISABLE_PUSH_NOTIFICATIONS precompilation symbol graphically via the UI (note that this the way its done in XCode 6.1):
Hope this helps other people out there in same situation.
In AppDelegate.m remove didRegisterForRemoteNotificationsWithDeviceToken and didFailToRegisterForRemoteNotificationsWithError. Working on PhoneGap 3.5
Following the advise above and in other places, this is what I did in Cordova 5.0.0
As result the warning disappeared and I haven't noticed any problem with the App.
Open platforms/ios/InfoganGardenAdmin/Classes/AppDelegate.m
Comment out line 116 to 137
example:
/* - Removed to disable push notification and Apple warning message
#ifndef DISABLE_PUSH_NOTIFICATIONS
- (void) application:(UIApplication*)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
// re-post ( broadcast )
NSString* token = [[[[deviceToken description]
stringByReplacingOccurrencesOfString:#"<" withString:#""]
stringByReplacingOccurrencesOfString:#">" withString:#""]
stringByReplacingOccurrencesOfString:#" " withString:#""];
[[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotification object:token];
}
- (void) application:(UIApplication*)application
didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
// re-post ( broadcast )
[[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotificationError object:error];
}
#endif
*/
It is most likely an issue with the version you are using, PhoneGap 3.5 has that same issue (PhoneGap is built on Cordova), you can view the discussion thread here
The current solution seems to be "use an older version"
The email is pretty vague and can be taken multiple ways plus if you are a new developer you may not have known about the wait time for Apple Store app reviews. See AppReviewTimes.
To Clarify: Its just a warning and you can ignore it if you don't use push notifications.
Don't try to fix what ain't broke. Plus all the solutions I could find didn't work.

The advertisingIdentifier and identifierForVendor return "00000000-0000-0000-0000-000000000000"

I've implemented this methods to get advertisingIdentifier and identifierForVendor:
- (NSString *) advertisingIdentifier
{
if (!NSClassFromString(#"ASIdentifierManager")) {
return [OpenUDID value];
}
return [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
}
- (NSString *) identifierForVendor
{
if ([[UIDevice currentDevice] respondsToSelector:#selector(identifierForVendor)]) {
return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
}
return #"";
}
- (BOOL)isAdvertisingTrackingEnabled
{
if (NSClassFromString(#"ASIdentifierManager") && ![[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]) {
return NO;
}
return YES;
}
On simulator everything is working as should be and I can get the 2 strings IDs representation.
But when I run from iPhone 3GS with iOS 6.0 (10A403), these 2 methods return "00000000-0000-0000-0000-000000000000" as identifier.
Already done:
Restarted the device
Removed the app and reinstalled
Created and Ad-Hoc build, installed, removed and installed again
Run this code from another app
Tested on iPad 2 with iOS 6.0 (10A403) and everything went ok (I've got the correct identifiers)
It appears to be a bug in iOS. Seeing the same issue on devices that have been upgraded over-the-air, but devices upgraded with Xcode or iTunes work as expected without zeros.
Tried similar steps as you, and the only common theme was over-the-air (bad) versus tethered upgrade (good).
Update: Users that move directly from iOS 5.1 to 6.1 over-the-air experience a different behavior. Every time the app is closed completely and restarted, a new value is being returned by identifierForVendor. This would be expected if the app was being uninstalled and reinstalled, but that's not the case.
Apple confirmed this bug in their system in response to a Technical Support Incident request. They said that identifierForVendor and advertisingIdentifier sometimes
returning all zeros can be seen both in development builds and apps downloaded over the air from the App Store. They have no work around and can't say when the problem will be fixed.
There are some situations where API returns empty response for ID like after device restore.
Suggestion is to postpone ID retreival, so you can call sometginh like this:
-(void)retrieveID
{
if (<check fails>)
[self performSelector:#"retrieveID" withObject:nil afterDelay:1.0];
}
And fetch ID later.

Resources