0%

Materials for APN


To add APN function to iShare, I try to find make a demo on Mac OS 10.10. Follow thoes listed steps, you can test your program
Objective-C post program or PHP.

Put this test code in your iOS program. delegate file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//registerd or not
if (![application isRegisteredForRemoteNotifications]) {
UIUserNotificationSettings *uns = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound) categories:nil];
[application registerUserNotificationSettings:uns];
//register
[application registerForRemoteNotifications];
}

return YES;
}

//register success,return deviceToken
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSLog(@"%@", deviceToken);
}

//register fail
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"%@", error);
}

//receive remote message
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"remote: %@", userInfo);
}

Binary Tree Maximum Path Sum

#Recursively can handle many kinds of question.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int maxPathUnit(struct TreeNode* node, int* result) {
if (!node) {
return 0;
}
// step 1
int left = maxPathUnit(node->left, result);
int right = maxPathUnit(node->right, result);
// step 2
int current = node->val;
current = node->val + left > current ? node->val + left : current;
current = node->val + right > current ? node->val + right : current;
current = node->val + left + right > current ? node->val + left + right : current;
// step 3
if (current > *result)
*result = current;
// step 4
int maxPath = node->val;
maxPath = node->val + left > maxPath ? node->val + left : maxPath;
maxPath = node->val + right > maxPath ? node->val + right : maxPath;
return maxPath;
}

int maxPathSum(struct TreeNode* root) {
int result = INT_MIN;
maxPathUnit(root, &result);
return result;
}

#Things about APN

Follow Material For Apple push notification can test your app with Development SSL Certificate easily. But when I move to Production SSL Certificate , I spand over 10 hour to figure out some problem. So I write the blog to help people who meetting the same problem like me.

##certification

###Use Development SSL Certificate

  • [x] iPhone developer certification
  • [x] apple development IOS Push Services

###Use Production SSL Certification

  • [x] iPhone Distribution certificaion
  • [x] Apple Production IOS Push Services
  • [x] apple store provisioning profile

Development SSL Certification and Production SSL Certification can exist at same time. But your app just can receive notification from one Certification.

##DeviceToken

deviceToken A token that identifies the device to APS. The token is an opaque data type because that is the form that the provider needs to submit to the APS servers when it sends a notification to a device. The APS servers require a binary format for performance reasons. Note that the device token is different from the uniqueIdentifier property of UIDevice because, for security and privacy reasons, it must change when the device is wiped.

####Important things

  • DeviceToken might change with time
  • DeviceToken might different in different app after iOS7
  • DeiceToken is different between Developer certification and Distribution certification
  • When you move to production SSL certification, remember change your code signing identity and provisioning in xcode

##Xcode
you need modify Build Settings->Code signing

Debug&Any iOS SDK should be iOS Developer
Release&Any iOS SDK should be iPhone Distribution XXXXX
Provisioning Profile should be Automatic or your apple store Provisioning profile

#final
rebuild your app with new Xcode code signing. You will get a new deviceToken different from deviceToken when you use Developer SSL certification.
Test your app with Cocoa-APNS-Test

#Hello World!

##test

###test2
$x^2=1$

Google

1
print 'hello world'

test test