Oscar Tong
Everything that has a beginning has an end.
- Control / Notification
- Airdrop
- (void)application:(UIApplication *)application
performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult result)) completionHandler
- (void)setMinimumBackgroundFetchInterval:(NSTimeInterval)minInterval;
... your app has up to 30 seconds of wall-clock time to perform the download operation and call the specified completion handler block ...
... the system uses the elapsed time to calculate power usage and data costs for your app’s background downloads. If your app takes a long time to call the completion handler, it may be given fewer future opportunities to fetch data in the future ...
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result)) completionHandler;
- (void)application:(UIApplication *)application
handleEventForBackgroundURLSession:(NSString *)identifier
completionHandler:(void (^)())completionHandler;
//identify yourself
MCPeerID *myPeerID = [[MCPeerID alloc] initWithName:@"Oscar"];
//create a session
MCSession *session = [[MCSession alloc] initWithPeer:myPeerID];
session.delegate = self;
//start advertising yourself
MCAdvertiserAssistant *assistant =
[[MCAdvertiserAssistant alloc] initWithServiceType:type discoveryInfo:nil session:session];
[assistant start];
//MCSessionStateNotConnected/Connecting/Connected)
session:peer:didChangeState:
MCBrowserViewController *browser = [[MCBrowserViewController] alloc]
initWithServiceType:serviceType
session:session];
browser.delegte = self;
[self presentViewController:browser animated:YES compiltion:nil];
- (BOOL)sendData:(NSData *)data
toPeers:(NSArray *)peerIDs
withMode:(MCSessionSendDataMode)mode
error:(NSError **)error
- (void)sendResourceAtURL:(NSURL *)resourceURL
toPeer:(NSArray *)peerIDs
withTimeout:(NSTimeInterval)timeout
completionHandler:(void (^)(NSError *error))completehandler
- (NSOutputStream *)startStreamstartStreamWithName:(NSString *)streamName
toPeer:(MCPeerID *)peerID
error:(NSError **)error
session:didReceiveData:fromPeer:
session:didReceiveResourceAtURL:fromPeer:
session:didReceiveStream:withName:fromPeer:
[session disconnect];
MCNearbyServiceAdvertiser *advertiser = [[MCNearbyServiceAdvertiser alloc]
initWithPeer:myPeerID
discoveryInfo:info
serviceType:type];
advertiser.delegate = self;
[advertiser startAdvertisingPeer];
MCNearbyServiceBrowser *browser = [[MCNearbyServiceBrowser alloc]
initWithPeer:myPeerID
serviceType:serviceType];
browser.delegate = self;
[browser startBrowsingForPeers];
- (void)browser:(MCNearbyServiceBrowser *)browser
foundPeer:(MCPeerID *)peerID
withDiscoveryInfo:(NSDictionary *)info
- (void)browser:(MCNearbyServiceBrowser *)browser lostPeer:(MCPeerID *)peerID
[browser invitePeer:peerID toSession:session withContext:context timeout:timeout];
- (void)advertiser:(MCNearbyServiceAdvertiser *)advertiser
didReceiveInvitationFromPeer:(MCPeerID *)peerID
withContext:(NSData *)context
invitationHandler:(void (^)(BOOL accept, MCSession *session))invitationHandler
//result.permission = "default"/"denied"/"granted"
//result.deviceToken = "...."
var result = window.safari.pushNotification.permission( websitePushID );
window.safari.pushNotification.requestPermission(
webServiceURL,
websitePushID,
userInfo,
callback
);
//if user confirms
callback({
permission: "granted",
deviceToken: "...."
});
{
"aps": {
"alert": {
"title": "Flight A109 Gate Changed",
"body": "Your gate has changed to A4",
"action": "View"
},
"url-args": ["gate-change", "A109"]
}
}
#import <JavaScriptCore/JavaScriptCore.h>
int main(){
JSContext *context = [[JSContext alloc] init];
JSValue *result = [context evaluateScript:@"2+2"];
NSLog(@"2+2=%d", [result toInt32]);
return 0;
}
var factorial = function(n){
if (n<0) return;
if (n===0) return 1;
return n * factorial(n-1);
};
NSString *factorialScript = ...;
[context evaluateScript:factorialScript];
JSValue *function = context[@"factorial"];
JSValue *result = [function callWithArguments:@[@5]];
NSLog(@"factorial(5) = %d", [result toInt32]);
context[@"makeNSColor"] = ^(NSDictionary *rgb){
float r = [color[@"red"] floatValue];
float g = [color[@"green"] floatValue];
float b = [color[@"blue"] floatValue];
return [NSColor colorWithRed:(r / 255.0f)
green:(g / 255.0f)
blue:(b / 255.0f)
alpha:1.0f];
};
var makeColor = function(rgb) {
return makrNSColor(rgb);
};
By Oscar Tong