<span id="Label3"></p><p><p>#import "AppDelegate.h"</p></p><p><p>#import "GexinSdk.h"</p></p><p><p>#import "ViewController.h"</p></p><p><p>@interface appdelegate () <GexinSdkDelegate></p></p><p><p>{</p></p><p><p>GEXINSDK *_gexinsdk;</p></p><p><p>}</p></p><p><p>@end</p></p><p><p></p></p><p><p>@implementation Appdelegate</p></p><p><p></p></p><p><p>Start a Push.</p></p><p><p>-(void) startgetui{</p></p><p><p>If (_gexinsdk==nil) {///first, the system will assign an empty address to the push, and if this thing exists, initialize it to Him.</p></p><p><p></p></p><p><p>Nserror *error=nil;</p></p><p><p>_gexinsdk=[gexinsdk</p></p><p><p>createsdkwithappid:@ "f84d2dtt68ahfenbrzio83"</p></p><p><p>appkey:@ "ofymp7ka9j6s0zkdeisls9"</p></p><p><p>appsecret:@ "fm0ezu7lce7fk7wa1r9jd9"</p></p><p><p>appversion:@ "1.0"</p></p><p><p>Delegate:self</p></p><p><p>Error:&error];//may fail to initialize due to a push Server's network delay, data errors, etc., and once initialization fails, assign a value to error</p></p><p><p></p></p><p><p></p></p><p><p>While (error!=nil) {//if the error is not empty, there is a value, that means that there was an error initializing the previous step, re-initialization</p></p><p><p>error=nil;</p></p><p><p>_GEXINSDK=[GEXINSDK createsdkwithappid:@ "f84d2dtt68ahfenbrzio83"</p></p><p><p>appkey:@ "ofymp7ka9j6s0zkdeisls9"</p></p><p><p>appsecret:@ "fm0ezu7lce7fk7wa1r9jd9"</p></p><p><p>appversion:@ "1.0"</p></p><p><p>Delegate:self</p></p><p><p>error:&error];</p></p><p><p>}</p></p><p><p>}</p></p><p><p>}</p></p><p><p>End</p></p><p><p>-(void) stopgetui{</p></p><p><p>If (_gexinsdk) {</p></p><p><p>[_GEXINSDK destroy];</p></p><p><p>_gexinsdk=nil;</p></p><p><p>}</p></p><p><p>}</p></p><p><p>Registered Principal//clientid Phone unique logo</p></p><p><p>-(void) gexinsdkdidregisterclient: (nsstring *) clientid{</p></p><p><p></p></p><p><p>[[nsuserdefaults Standarduserdefaults]setvalue:clientid forkey:kpushuserid];</p></p><p><p>Viewcontroller *v= (viewcontroller*) [uiapplication sharedapplication].keywindow.rootviewcontroller;</p></p><p><p>self.window.rootviewcontroller=v;</p></p><p><p></p></p><p><p>NSLog (@ "registered ===clientid====#########=====%@", clientId);</p></p><p><p>}</p></p><p><p>Register error----> similar to a fault tolerance mechanism</p></p><p><p>-(void) gexinsdkdidoccurerror: (nserror *) error{</p></p><p><p></p></p><p><p>}</p></p><p><p>Send Message</p></p><p><p>-(void) gexinsdkdidsendmessage: (nsstring *) messageId result: (int) result{</p></p><p><p></p></p><p><p>}</p></p><p><p></p></p><p><p>When you receive a push message</p></p><p><p>-(void) gexinsdkdidreceivepayload: (nsstring *) payloadid fromapplication: (nsstring *) appid{</p></p><p><p></p></p><p><p>NSLog (@ "gexinsdkdidreceivepayload:%@", payloadid);</p></p><p><p></p></p><p><p>NSData *PAYLOAD=[_GEXINSDK retrivepayloadbyid:payloadid];</p></p><p><p>NSString *payloadmsg=nil;</p></p><p><p>If (payload) {</p></p><p><p>Payloadmsg=[[nsstring alloc]initwithbytes:payload.bytes</p></p><p><p>Length:payload.length</p></p><p><p>encoding:nsutf8stringencoding];</p></p><p><p>}</p></p><p><p>NSLog (@ "received message%@", payloadmsg);</p></p><p><p></p></p><p><p>Nsdictionary *dic = [nsjsonserialization jsonobjectwithdata:payload options:0 error:nil];</p></p><p><p></p></p><p><p>[[nsnotificationcenter Defaultcenter]postnotificationname:hjiedan object:dic userinfo:nil];</p></p><p><p>}</p></p><p><p></p></p><p><p>-(void) application: (uiapplication *) application didregisterforremotenotificationswithdevicetoken: (NSData *) Devicetoken</p></p><p><p>{//if successful, go to register a push</p></p><p><p>NSString *token=[[devicetoken Description]stringbytrimmingcharactersinset:[nscharacterset charactersetwithcharactersinstring:@ "<>"];</p></p><p><p>NSString *strdevicetoken=[token stringbyreplacingoccurrencesofstring:@ "" withstring:@ ""];</p></p><p><p>NSLog (@ "devicetoken===-----------===%@", strdevicetoken);</p></p><p><p></p></p><p><p>[self startgetui];</p></p><p><p></p></p><p><p>If (_gexinsdk!=nil) {</p></p><p><p>[_GEXINSDK registerdevicetoken:strdevicetoken];</p></p><p><p>}</p></p><p><p>}</p></p><p><p>-(void) application: (uiapplication *) application didfailtoregisterforremotenotificationswitherror: (NSError *) Error</p></p><p><p>{//if It fails, leave this thing Blank.</p></p><p><p>If (_gexinsdk!=nil) {</p></p><p><p>[_GEXINSDK registerdevicetoken:@ ""];</p></p><p><p>}</p></p><p><p>}</p></p><p><p>-(void) application: (uiapplication *) application didreceivelocalnotification: (uilocalnotification *) notification</p></p><p><p>{</p></p><p><p>Set the number of red dots</p></p><p><p>[[uiapplication sharedapplication] setapplicationiconbadgenumber:0];</p></p><p><p>}</p></p><p><p>-(void) application: (uiapplication *) application didreceiveremotenotification: (nsdictionary *) userInfo Fetchcompletionhandler: (void (^) (uibackgroundfetchresult result)) Completionhandler</p></p><p><p>{</p></p><p><p>NSString *payloadmsg=[userinfo objectforkey:@ "payload"];</p></p><p><p>NSLog (@ "did:%@", Payloadmsg);//print out the received Send message</p></p><p><p></p></p><p><p>Completionhandler (uibackgroundfetchresultnewdata);</p></p><p><p>}</p></p><p><p></p></p><p><p>-(BOOL) application: (uiapplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions {</p></p><p><p>Override point for customization after application Launch.</p></p><p><p></p></p><p><p>Uiviewcontroller *_viewcontroller = [[uiviewcontroller alloc] init];</p></p><p><p>Uinavigationcontroller *_navviewcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:_ viewcontroller];</p></p><p><p>_navviewcontroller.navigationbar.hidden = YES;</p></p><p><p></p></p><p><p>[self Startgetui];//create a push</p></p><p><p>#warning Registration push</p></p><p><p>Register push</p></p><p><p>If ([[[[uidevice currentdevice] systemversion] floatvalue] >= 8.0) {</p></p><p><p>Uiusernotificationsettings *uns = [uiusernotificationsettings settingsfortypes: (uiusernotificationtypealert| uiusernotificationtypebadge| Uiusernotificationtypesound) categories:nil];</p></p><p><p>[[uiapplication sharedapplication] registerforremotenotifications]; 8.0 Remote Token Registration</p></p><p><p>[[uiapplication sharedapplication] registerusernotificationsettings:uns];</p></p><p><p></p></p><p><p>} else {</p></p><p><p>Uiremotenotificationtype Apn_type = (uiremotenotificationtype) (uiremotenotificationtypealert| uiremotenotificationtypesound| uiremotenotificationtypebadge);</p></p><p><p>[[uiapplication sharedapplication] registerforremotenotificationtypes:apn_type];</p></p><p><p>}//registration Complete</p></p><p><p></p></p><p><p>[application.keyWindow.rootViewController.view addsubview:_navviewcontroller.view];</p></p><p><p></p></p><p><p>Dnwrootviewcontroller *hvc=[dnwrootviewcontroller new];</p></p><p><p>Self.window=[[uiwindow Alloc]initwithframe:[uiscreen mainscreen].bounds];</p></p><p><p>Self.window.backgroundcolor=[uicolor whitecolor];</p></p><p><p>[self.window makekeyandvisible];</p></p><p><p>_window.rootviewcontroller=hvc;</p></p><p><p></p></p><p><p>/*******************************************************************/</p></p><p><p>#pragma mark-local notification ###########</p></p><p><p></p></p><p><p>/*</p></p><p><p>Uilocalnotification *notification=[[uilocalnotification alloc] init];</p></p><p><p>If (notification!=nil) {</p></p><p><p>NSDate *now = [nsdate date];</p></p><p><p>Notice from now on, 10 seconds later</p></p><p><p>Notification.firedate=[now datebyaddingtimeinterval:10];</p></p><p><p>Use local time zone</p></p><p><p>Notification.timezone=[nstimezone defaulttimezone];</p></p><p><p>[email protected] "top prompt content, notice time";</p></p><p><p>Notification tones Use the default</p></p><p><p>Notification.soundname= uilocalnotificationdefaultsoundname;</p></p><p><p>Notification.alertaction=nslocalizedstring (@ "you Lock screen, notice time is up", nil);</p></p><p><p>This notification to the time when your app displays the number in the upper right corner.</p></p><p><p>Notification.applicationiconbadgenumber = 1;</p></p><p><p>Add key adds key to this notification to make it easier to cancel Halfway. Nfkey This key is my own random.</p></p><p><p>If your notice will not be the time to manually cancel the next two lines of code you can not Write.</p></p><p><p>Nsdictionary *dict =[nsdictionary dictionarywithobjectsandkeys:[nsnumber numberwithint:notificationtag],@ "n Fkey ", nil];</p></p><p><p>[notification setuserinfo:dict];</p></p><p><p>Start this notification</p></p><p><p>[[uiapplication sharedapplication] schedulelocalnotification:notification];</p></p><p><p>This sentence is really especially important. If you do not add this, notice to the time, found the top of the notification bar tips where there is, and then you go through the notification bar, and then you find the notification bar inside there is this hint</p></p><p><p>Unless you remove it manually, this is certainly not what we want. It would be nice to add this sentence. Many of the online code is not, it is more depressed.</p></p><p><p>[notification release];</p></p><p><p>}</p></p><p><p>*/</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p>Return YES;</p></p><p><p>}</p></p><p><p></p></p><p><p></p></p><p><p>-(void) applicationwillresignactive: (uiapplication *) Application {</p></p><p><p>Sent when the application are about to move from active to inactive State. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS Message) or when the US Er quits the application and it begins the transition to the background State.</p></p><p><p>Use the This method to the pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the Game.</p></p><p><p>}</p></p><p><p></p></p><p><p>-(void) applicationdidenterbackground: (uiapplication *) Application {</p></p><p><p>Use the This method to release the shared resources, save user data, invalidate timers, and store enough application state info Rmation to the restore your application to the it is terminated later.</p></p><p><p>If your application supports background execution, This method is called instead of Applicationwillterminate:when the User Quits.</p></p><p><p>}</p></p><p><p></p></p><p><p>-(void) applicationwillenterforeground: (uiapplication *) Application {</p></p><p><p>Called as part of the transition from the background to the inactive state; Here's can undo many of the changes made on entering the Background.</p></p><p><p>}</p></p><p><p></p></p><p><p>-(void) applicationdidbecomeactive: (uiapplication *) Application {</p></p><p><p>Restart any tasks this were paused (or not yet started) while the application is Inactive. If the application is previously in the background, optionally refresh the user interface.</p></p><p><p>}</p></p><p><p></p></p><p><p>-(void) applicationwillterminate: (uiapplication *) Application {</p></p><p><p>Called when the application are about to Terminate. Save Data If Appropriate. See also Applicationdidenterbackground:.</p></p><p><p>Saves changes in the application ' s managed object context before the application Terminates.</p></p><p><p>[self savecontext];</p></p><p><p>}</p></p><p><p></p></p><p><p>#pragma mark-core Data Stack</p></p><p><p></p></p><p><p>@synthesize Managedobjectcontext = _managedobjectcontext;</p></p><p><p>@synthesize Managedobjectmodel = _managedobjectmodel;</p></p><p><p>@synthesize Persistentstorecoordinator = _persistentstorecoordinator;</p></p><p><p></p></p><p><p>-(nsurl *) Applicationdocumentsdirectory {</p></p><p><p>The directory the application uses to store the Core Data store File. This code uses a directory named " -23.about_car" in the application ' s documents directory.</p></p><p><p>return [[[nsfilemanager defaultmanager] urlsfordirectory:nsdocumentdirectory indomains:nsuserdomainmask] lastObject ];</p></p><p><p>}</p></p><p><p></p></p><p><p>-(nsmanagedobjectmodel *) Managedobjectmodel {</p></p><p><p>The managed object model for the Application. It is a fatal error for the application not to be able to find and load its model.</p></p><p><p>If (_managedobjectmodel! = Nil) {</p></p><p><p>Return _managedobjectmodel;</p></p><p><p>}</p></p><p><p>Nsurl *modelurl = [[nsbundle mainbundle] urlforresource:@ "about_car" withextension:@ "momd"];</p></p><p><p>_managedobjectmodel = [[nsmanagedobjectmodel alloc] initwithcontentsofurl:modelurl];</p></p><p><p>Return _managedobjectmodel;</p></p><p><p>}</p></p><p><p></p></p><p><p>-(nspersistentstorecoordinator *) Persistentstorecoordinator {</p></p><p><p>The persistent store coordinator for the Application. This implementation creates and return a coordinator, has added the store for the application to it.</p></p><p><p>If (_persistentstorecoordinator! = Nil) {</p></p><p><p>Return _persistentstorecoordinator;</p></p><p><p>}</p></p><p><p></p></p><p><p>Create the Coordinator and store</p></p><p><p></p></p><p><p>_persistentstorecoordinator = [[nspersistentstorecoordinator alloc] initwithmanagedobjectmodel:[self managedobjectmodel]];</p></p><p><p>Nsurl *storeurl = [[self applicationdocumentsdirectory] urlbyappendingpathcomponent:@ "about_car.sqlite"];</p></p><p><p>Nserror *error = nil;</p></p><p><p>NSString *failurereason = @ "there is an error creating or loading the application ' s saved data.";</p></p><p><p>If (![ _persistentstorecoordinator addpersistentstorewithtype:nssqlitestoretype Configuration:nil URL:storeURL options: Nil Error:&error]) {</p></p><p><p>Report any error we Got.</p></p><p><p>Nsmutabledictionary *dict = [nsmutabledictionary dictionary];</p></p><p><p>dict[nslocalizeddescriptionkey] = @ "Failed to initialize the application ' s saved data";</p></p><p><p>dict[nslocalizedfailurereasonerrorkey] = failurereason;</p></p><p><p>dict[nsunderlyingerrorkey] = error;</p></p><p><p>Error = [nserror errorwithdomain:@ "your_error_domain" code:9999 userinfo:dict];</p></p><p><p>Replace this with code to handle the error appropriately.</p></p><p><p>Abort () causes the application to generate a crash log and Terminate. You should don't use the This function in a shipping application, although it could be useful during.</p></p><p><p>NSLog (@ "unresolved error%@,%@", error, [error userInfo]);</p></p><p><p>Abort ();</p></p><p><p>}</p></p><p><p></p></p><p><p>Return _persistentstorecoordinator;</p></p><p><p>}</p></p><p><p></p></p><p><p></p></p><p><p>-(nsmanagedobjectcontext *) Managedobjectcontext {</p></p><p><p>Returns the managed object context for the application (which are already bound to the persistent store coordinator for The Application.)</p></p><p><p>If (_managedobjectcontext! = Nil) {</p></p><p><p>Return _managedobjectcontext;</p></p><p><p>}</p></p><p><p></p></p><p><p>Nspersistentstorecoordinator *coordinator = [self persistentstorecoordinator];</p></p><p><p>If (!coordinator) {</p></p><p><p>Return nil;</p></p><p><p>}</p></p><p><p>_managedobjectcontext = [[nsmanagedobjectcontext alloc] init];</p></p><p><p>[_managedobjectcontext setpersistentstorecoordinator:coordinator];</p></p><p><p>Return _managedobjectcontext;</p></p><p><p>}</p></p><p><p></p></p><p><p>#pragma mark-core Data Saving support</p></p><p><p></p></p><p><p>-(void) Savecontext {</p></p><p><p>Nsmanagedobjectcontext *managedobjectcontext = self.managedobjectcontext;</p></p><p><p>If (managedobjectcontext! = Nil) {</p></p><p><p>Nserror *error = nil;</p></p><p><p>If ([managedobjectcontext haschanges] &&![ Managedobjectcontext Save:&error]) {</p></p><p><p>Replace This implementation with code to handle the error appropriately.</p></p><p><p>Abort () causes the application to generate a crash log and Terminate. You should don't use the This function in a shipping application, although it could be useful during.</p></p><p><p>NSLog (@ "unresolved error%@,%@", error, [error userInfo]);</p></p><p><p>Abort ();</p></p><p><p>}</p></p><p><p>}</p></p><p><p>}</p></p><p><p></p></p><p><p>@end</p></p><p><p></p></p><p><p>App file content for push content</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service