Skip to content

Commit ef6f3b4

Browse files
committed
Started work in push for iOS
1 parent ca3a8b2 commit ef6f3b4

5 files changed

+158
-6
lines changed

codenameone_library_appended.properties

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
#is an appended type property.
44
#
55
#Wed Jan 09 17:59:31 IST 2013
6+
7+
# Required libs for Parse iOS native SDK (see also https://parse.com/apps/quickstart#parse_push/ios/native/existing)
8+
codename1.arg.ios.add_libs=Foundation.framework;AudioToolbox.framework;CFNetwork.framework;CoreGraphics.framework;CoreLocation.framework;QuartzCore.framework;Security.framework;StoreKit.framework;SystemConfiguration.framework;Accounts.framework;Social.framework;libz.dylib;libsqlite3.dylib;Parse.a;Bolts.a

codenameone_library_required.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
#needs the google play services but the main project marked this property to false
66
#The refresh cn1lib action will fail.
77
#
8-
#Wed Jan 09 17:59:31 IST 2013
8+
#Wed Jan 09 17:59:31 IST 2013

test/CN1TestApp/codenameone_settings.properties

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ codename1.ios.release.provision=D\:\\Workspace\\projects\\parse4cn1\\test\\CN1Te
55
codename1.arg.rim.obfuscation=false
66
codename1.j2me.nativeTheme=nbproject/nativej2me.res
77
codename1.arg.ios.project_type=ios
8+
codename1.arg.ios.glAppDelegateHeader=\#import "Parse.h"
89
codename1.arg.ios.interface_orientation=UIInterfaceOrientationPortrait\:UIInterfaceOrientationPortraitUpsideDown\:UIInterfaceOrientationLandscapeLeft\:UIInterfaceOrientationLandscapeRight
910
codename1.displayName=parse4cn1TestApp
1011
guiResource=theme.res

test/ParsePushTestApp/HowTo_EnablePushForAndroid.txt

-5
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ android.xpermissions =
5454
android:name="com.parse4cn1.TestApp.permission.C2D_MESSAGE" />
5555
<uses-permission android:name="com.parse4cn1.TestApp.permission.C2D_MESSAGE" />
5656

57-
58-
Add activity attribute
59-
60-
android.xactivity=android:alwaysRetainTaskState="true"
61-
6257
So that activity is opened in existing task when push message is opened.
6358

6459
2. Invoke <TODO: Method name> to enable push support
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
Tutorial: http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
2+
3+
Issue: no valid aps:
4+
1. https://www.google.nl/webhp?sourceid=chrome-instant&rlz=1C1CHFX_enNL640NL640&ion=1&espv=2&ie=UTF-8#q=no%20valid%20aps-environment%20entitlement%20string%20found%20for%20application
5+
2. Manually signing http://stackoverflow.com/questions/5681172/bundle-identifier-and-push-certificate-aps-environment-entitlement-error
6+
http://stackoverflow.com/questions/15634188/resigning-an-ios-provisioning-profile
7+
http://stackoverflow.com/questions/6896029/re-sign-ipa-iphone
8+
- Initial result: code object is not signed at all
9+
10+
Error: "no valid 'aps-environment' entitlement string found for application"
11+
12+
Tips
13+
- Registration for push different in iOS 8: http://stackoverflow.com/questions/4086599/why-didregisterforremotenotificationswithdevicetoken-is-not-called
14+
15+
Device token registration not working
16+
- (@"" trick) http://stackoverflow.com/questions/31116849/parse-com-devicetoken-and-pfinstallation-not-saved See also: http://stackoverflow.com/questions/31181428/parse-installation-table-not-registering-devicetoken
17+
18+
19+
Issues: Creating certificates
20+
1. Unknown authority --> Export to .p12 option not visible
21+
http://stackoverflow.com/questions/13820680/this-certificate-was-signed-by-an-unknown-authority
22+
23+
2. No certificate found (instructions from Parse are not crystal clear). You need a new separate one for this purpose
24+
http://stackoverflow.com/questions/25223644/no-certificates-are-available-when-adding-ios-provisioning-profile-for-parse-p
25+
26+
=================
27+
Steps
28+
29+
30+
// ios.add_libs
31+
Foundation.framework;AudioToolbox.framework;CFNetwork.framework;CoreGraphics.framework;CoreLocation.framework;QuartzCore.framework;Security.framework;StoreKit.framework;SystemConfiguration.framework;libz.dylib;libsqlite3.dylib;Parse.a;Bolts.a
32+
33+
//Extra add_libs: Parse.a and Bolts.a (renamed from original non .a files)
34+
35+
// If you're using the -ObjC linker flag required by some third-party libraries, add these as well:
36+
// ios.add_libs
37+
Accounts.framework;Social.framework
38+
39+
// Also remember to enable -ObjC linker flag with
40+
// ios.objC
41+
42+
// ios.glAppDelegateHeader
43+
#import "Parse.h" // <Parse/Parse.h> --> "Parse.h" since included libraries are flattened
44+
45+
46+
// ios.afterFinishLaunching
47+
[Parse setApplicationId:@"j1KMuH9otZlHcPncU9dZ1JFH7cXL8K5XUiQQ9ot8" clientKey:@"V6ZUyBtfERtzbq6vjeAb13tiFYij980HN9nQTWGB"];
48+
49+
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
50+
UIUserNotificationTypeBadge |
51+
UIUserNotificationTypeSound);
52+
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
53+
categories:nil];
54+
[application registerUserNotificationSettings:settings];
55+
[application registerForRemoteNotifications];
56+
57+
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Wait" message:@"Are you sure you want to delete this. This action cannot be undone" delegate:nil cancelButtonTitle:@"Delete" otherButtonTitles:@"Cancel", nil];
58+
[alert show];
59+
[alert autorelease];
60+
61+
// ios.glAppDelegateBody
62+
// Following three methods should be added without line breaks:
63+
64+
65+
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {PFInstallation *currentInstallation = [PFInstallation currentInstallation]; [currentInstallation setDeviceTokenFromData:deviceToken]; currentInstallation.channels = @[@"global"];[currentInstallation saveInBackground];} - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { if (error.code == 3010) { NSLog(@"Push notifications are not supported in the iOS Simulator.");} else { NSLog(@"application:didFailToRegisterForRemoteNotificationsWithError: %@", error);}} - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {[PFPush handlePush:userInfo];}
66+
67+
// With line breaks for readability of tutorial
68+
69+
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
70+
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
71+
currentInstallation.deviceToken = @""; // Tip from stackoverflow!!!
72+
[currentInstallation setDeviceTokenFromData:deviceToken];
73+
currentInstallation.channels = @[@"global"];
74+
[currentInstallation saveInBackground];
75+
}
76+
77+
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
78+
if (error.code == 3010) {
79+
NSLog(@"Push notifications are not supported in the iOS Simulator.");
80+
} else {
81+
// show some alert or otherwise handle the failure to register.
82+
NSLog(@"application:didFailToRegisterForRemoteNotificationsWithError: %@", error);
83+
}
84+
}
85+
86+
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
87+
[PFPush handlePush:userInfo];
88+
}
89+
90+
// With popups
91+
92+
93+
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { PFInstallation *currentInstallation = [PFInstallation currentInstallation]; [currentInstallation setDeviceTokenFromData:deviceToken]; currentInstallation.channels = @[@"global"]; [currentInstallation saveInBackground]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Installation" message:@"Installation saved in background" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil]; [alert show]; [alert autorelease]; } - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Registration Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil]; [alert show]; [alert autorelease]; if (error.code == 3010) { NSLog(@"Push notifications are not supported in the iOS Simulator."); } else { NSLog(@"application:didFailToRegisterForRemoteNotificationsWithError: %@", error); }} - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notification" message:@"Received push while app was running" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil]; [alert show]; [alert autorelease]; [PFPush handlePush:userInfo];}
94+
95+
// With debugging
96+
97+
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
98+
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
99+
currentInstallation.deviceToken = @""; // Tip from stackoverflow!!!
100+
[currentInstallation setDeviceTokenFromData:deviceToken];
101+
currentInstallation.channels = @[@"global"];
102+
103+
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Device token" message:currentInstallation.deviceToken delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
104+
[alert show];
105+
[alert autorelease];
106+
107+
[currentInstallation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
108+
if (succeeded) {
109+
110+
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Installation saved" message:@"Installation saved in background" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
111+
[alert show];
112+
[alert autorelease];
113+
114+
}
115+
116+
if (error) {
117+
118+
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Installation not saved" message:error.localizedDescription delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
119+
[alert show];
120+
[alert autorelease];
121+
122+
}
123+
}];
124+
}
125+
126+
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
127+
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Registration Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
128+
[alert show];
129+
[alert autorelease];
130+
}
131+
132+
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
133+
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notification" message:@"Received push while app was running" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil]; [alert show];
134+
[alert autorelease];
135+
[PFPush handlePush:userInfo];
136+
}
137+
138+
139+
// Compressed
140+
141+
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { PFInstallation *currentInstallation = [PFInstallation currentInstallation]; currentInstallation.deviceToken = @""; [currentInstallation setDeviceTokenFromData:deviceToken]; currentInstallation.channels = @[@"global"]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Device token" message:currentInstallation.deviceToken delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil]; [alert show]; [alert autorelease]; [currentInstallation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { if (succeeded) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Installation saved" message:@"Installation saved in background" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil]; [alert show]; [alert autorelease]; } if (error) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Installation not saved" message:error.localizedDescription delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil]; [alert show]; [alert autorelease]; }}];} - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Registration Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil]; [alert show]; [alert autorelease]; } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notification" message:@"Received push while app was running" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil]; [alert show]; [alert autorelease]; [PFPush handlePush:userInfo]; }
142+
143+
144+
Utils
145+
- NSDictionary to JSON string
146+
http://stackoverflow.com/questions/6368867/generate-json-string-from-nsdictionary
147+
148+
149+
Receiving push in different app states
150+
http://stackoverflow.com/questions/23168345/detect-if-application-didreceiveremotenotification-fetchcompletionhandler-was
151+
http://stackoverflow.com/questions/31450403/didreceiveremotenotification-not-working-in-the-background
152+
https://parse.com/docs/ios/guide#push-notifications-receiving-pushes
153+
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html

0 commit comments

Comments
 (0)